xiangfu0 commented on code in PR #11151:
URL: https://github.com/apache/pinot/pull/11151#discussion_r1271578406


##########
pinot-query-planner/src/test/resources/queries/JoinPlans.json:
##########
@@ -313,22 +313,78 @@
       },
       {
         "description": "Correlated join",
-        "sql": "EXPLAIN PLAN FOR SELECT a.col1 FROM a WHERE a.col4 > (SELECT 
0.5 * SUM(b.col3) FROM b WHERE b.col2 = a.col2 AND b.col1 = a.col1)",
+        "sql": "EXPLAIN PLAN FOR SELECT a.col1 FROM a WHERE a.col4 > (SELECT 
CAST(0.5 * SUM(b.col3) AS DECIMAL(19, 1)) FROM b WHERE b.col2 = a.col2 AND 
b.col1 = a.col1)",

Review Comment:
   This query failed due to a de-correlation issue for type mismatch of 
`DECIMAL(19, 1)` and ``DECIMAL(21, 1)`
   ```
   
   java.lang.AssertionError: Cannot add expression of different type to set:
   set type is RecordType(VARCHAR NOT NULL col1, VARCHAR NOT NULL col2, INTEGER 
NOT NULL col3, DECIMAL(1000, 0) NOT NULL col4, BOOLEAN NOT NULL col5, INTEGER 
NOT NULL col6, BIGINT NOT NULL ts, DECIMAL(21, 1) EXPR$0) NOT NULL
   expression type is RecordType(VARCHAR NOT NULL col1, VARCHAR NOT NULL col2, 
INTEGER NOT NULL col3, DECIMAL(1000, 0) NOT NULL col4, BOOLEAN NOT NULL col5, 
INTEGER NOT NULL col6, BIGINT NOT NULL ts, DECIMAL(19, 1) EXPR$0) NOT NULL
   set is 
rel#6543:LogicalCorrelate.(left=HepRelVertex#6533,right=HepRelVertex#6542,correlation=$cor0,joinType=left,requiredColumns={0,
 1})
   expression is LogicalProject(col1=[$0], col2=[$1], col3=[$2], col4=[$3], 
col5=[$4], col6=[$5], ts=[$6], EXPR$0=[*(0.5:DECIMAL(2, 1), $7)])
     LogicalCorrelate(correlation=[$cor0], joinType=[left], 
requiredColumns=[{0, 1}])
       LogicalTableScan(table=[[a]])
       LogicalAggregate(group=[{}], agg#0=[SUM($0)])
         LogicalProject(col3=[$2])
           LogicalFilter(condition=[AND(=($1, $cor0.col2), =($0, $cor0.col1))])
             LogicalTableScan(table=[[b]])
   
   
        at 
org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:391)
        at 
org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:60)
        at 
org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:269)
        at 
org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:284)
        at 
org.apache.calcite.sql2rel.RelDecorrelator$AdjustProjectForCountAggregateRule.onMatch2(RelDecorrelator.java:2703)
        at 
org.apache.calcite.sql2rel.RelDecorrelator$AdjustProjectForCountAggregateRule.onMatch(RelDecorrelator.java:2610)
        at 
org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:337)
        at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:556)
        at 
org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:420)
        at 
org.apache.calcite.plan.hep.HepPlanner.executeRuleInstance(HepPlanner.java:243)
        at 
org.apache.calcite.plan.hep.HepInstruction$RuleInstance$State.execute(HepInstruction.java:178)
        at 
org.apache.calcite.plan.hep.HepPlanner.lambda$executeProgram$0(HepPlanner.java:211)
        at 
com.google.common.collect.ImmutableList.forEach(ImmutableList.java:422)
        at 
org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:210)
        at 
org.apache.calcite.plan.hep.HepProgram$State.execute(HepProgram.java:118)
        at 
org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:205)
        at 
org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:191)
        at 
org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:291)
        at 
org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:230)
        at 
org.apache.pinot.query.QueryEnvironment.decorrelateIfNeeded(QueryEnvironment.java:282)
        at 
org.apache.pinot.query.QueryEnvironment.compileQuery(QueryEnvironment.java:275)
        at 
org.apache.pinot.query.QueryEnvironment.explainQuery(QueryEnvironment.java:202)
        at 
org.apache.pinot.query.QueryEnvironment.explainQuery(QueryEnvironment.java:220)
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to