[ https://issues.apache.org/jira/browse/CALCITE-5568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17699424#comment-17699424 ]
libopeng commented on CALCITE-5568: ----------------------------------- [~libenchao] I've seen this solution on other projects([dremio|https://github.com/dremio/dremio-oss/blob/master/sabot/kernel/src/main/java/org/apache/calcite/sql2rel/DremioRelDecorrelator.java#L105]), and in this case it worked correctly, but I don't know if it would make a mistake in some scenarios {code:java} public @Nullable Frame decorrelateRel(Values rel, boolean isCorVarDefined) { return decorrelateRel((RelNode)rel, isCorVarDefined); } {code} > Decorrelate will fail. If the RelNode tree has LogicalValues > ------------------------------------------------------------ > > Key: CALCITE-5568 > URL: https://issues.apache.org/jira/browse/CALCITE-5568 > Project: Calcite > Issue Type: Bug > Reporter: libopeng > Priority: Major > > Decorrelate will fail. If the RelNode tree has LogicalValues > case: > {code:java} > SELECT > ( > SELECT > ( SUM ( "tbl2"."count" ) ) AS "SUM" > FROM > ( > SELECT > ( > SELECT > ( COUNT ( "tbl2"."id" ) ) AS "COUNT" > FROM > "trip_order" AS "tbl2" > WHERE > "tbl1"."province" = "tbl2"."province" > ) AS "count", > ( "tbl1"."province" ) AS "province" > FROM > "trip_order" AS "tbl1" > ) AS "tbl2" > ) AS "sub_1" > {code} > after decorrelate > (org.apache.calcite.sql2rel.RelDecorrelator#decorrelateQuery(org.apache.calcite.rel.RelNode, > org.apache.calcite.tools.RelBuilder)) > {code:java} > LogicalProject(sub_1=[$1]) > LogicalJoin(condition=[true], joinType=[left]) > LogicalValues(tuples=[[{ 0 }]]) <---- > LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)]) > LogicalAggregate(group=[{}], SUM=[SUM($0)]) > LogicalProject(count=[$10]) > LogicalProject(id=[$0], gmt_create=[$1], service_begin=[$2], > driver_id=[$3], passenger_id=[$4], province=[$5], city=[$6], > service_minute=[$7], service_mileage=[$8], order_amount=[$9], $f0=[$10]) > LogicalProject(id=[$0], gmt_create=[$1], service_begin=[$2], > driver_id=[$3], passenger_id=[$4], province=[$5], city=[$6], > service_minute=[$7], service_mileage=[$8], order_amount=[$9], $f0=[$10]) > LogicalCorrelate(correlation=[$cor0], joinType=[left], > requiredColumns=[{5}]) <---- See here, the decorrelate didn't work > LogicalTableScan(table=[[trip_order]]) > LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)]) > LogicalAggregate(group=[{}], COUNT=[COUNT()]) > LogicalFilter(condition=[=($cor0.province, $5)]) > LogicalTableScan(table=[[trip_order]]){code} > LogicalCorrelate will not be processed when the RelNode tree has > LogicalValues > [https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java#L491] > > Is this as expected? > > > > -- This message was sent by Atlassian Jira (v8.20.10#820010)