Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6525] Query with one-to-many join of measure to regular table (draft) #3952

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6062,7 +6062,6 @@ private HepProgram getTransitiveProgram() {
.check();
}

@Disabled
@Test void testMeasureJoin() {
final String sql = "with deptm as\n"
+ " (select deptno, name, avg(char_length(name)) as measure m\n"
Expand All @@ -6075,7 +6074,7 @@ private HepProgram getTransitiveProgram() {
t.withOperatorTable(opTab ->
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
SqlLibrary.STANDARD, SqlLibrary.CALCITE))) // for AGGREGATE
.withRule(MeasureRules.AGGREGATE,
.withRule(MeasureRules.AGGREGATE2,
CoreRules.PROJECT_MERGE,
MeasureRules.PROJECT)
.check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6753,10 +6753,11 @@ LogicalProject(DEPTNO=[$0], C1=[$1])
</TestCase>
<TestCase name="testMeasureJoin">
<Resource name="sql">
<![CDATA[select deptno, aggregate(m) as m
from (select deptno, name, avg(char_length(name)) as measure m
from dept)
join emp using (deptno)
<![CDATA[with deptm as
(select deptno, name, avg(char_length(name)) as measure m
from dept)
select deptno, aggregate(m) as m
from deptm join emp using (deptno)
group by deptno]]>
</Resource>
<Resource name="planBefore">
Expand All @@ -6774,7 +6775,7 @@ LogicalProject(DEPTNO=[$0], M=[$1])
<![CDATA[
LogicalProject(DEPTNO=[$0], M=[$1])
LogicalAggregate(group=[{0}], agg#0=[SINGLE_VALUE($1)])
LogicalProject($f0=[$0], $f2=[M2X($2, SAME_PARTITION($0))])
LogicalProject($f0=[$0], $f2=[TODO($2, SAME_PARTITION($0))])
LogicalJoin(condition=[=($0, $10)], joinType=[inner])
LogicalProject(DEPTNO=[$0], NAME=[$1], M=[V2M(CAST(/(SUM(CHAR_LENGTH($1)), COUNT(CHAR_LENGTH($1)))):INTEGER NOT NULL)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
Expand Down
8 changes: 8 additions & 0 deletions core/src/test/resources/sql/measure.iq
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ where job = 'MANAGER';

!ok

# [CALCITE-6525] Query with one-to-many join of measure to regular table
with deptm as
(select deptno, dname, avg(char_length(dname)) as measure m
from dept)
select aggregate(m) as m
from deptm join emp using (deptno);
!ok

# Measure that references another measure
select *
from (
Expand Down
Loading