[jira] [Work logged] (HIVE-27305) AssertionError in Calcite during planning for incremental rebuild of materialized view with aggregate on decimal column
[ https://issues.apache.org/jira/browse/HIVE-27305?focusedWorklogId=860365&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-860365 ] ASF GitHub Bot logged work on HIVE-27305: - Author: ASF GitHub Bot Created on: 03/May/23 15:03 Start Date: 03/May/23 15:03 Worklog Time Spent: 10m Work Description: kasakrisz merged PR #4277: URL: https://github.com/apache/hive/pull/4277 Issue Time Tracking --- Worklog Id: (was: 860365) Time Spent: 1h (was: 50m) > AssertionError in Calcite during planning for incremental rebuild of > materialized view with aggregate on decimal column > --- > > Key: HIVE-27305 > URL: https://issues.apache.org/jira/browse/HIVE-27305 > Project: Hive > Issue Type: Bug > Components: CBO, Materialized views >Reporter: Krisztian Kasa >Assignee: Krisztian Kasa >Priority: Major > Labels: pull-request-available > Time Spent: 1h > Remaining Estimate: 0h > > {code} > set hive.support.concurrency=true; > set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; > set hive.materializedview.rewriting.sql=false; > create table t1(a int, b decimal(7,2)) stored as orc TBLPROPERTIES > ('transactional'='true'); > insert into t1(a, b) values(1, 1); > create materialized view mat1 stored as orc TBLPROPERTIES > ('transactional'='true') as > select t1.a, sum(t1.b) from t1 > group by t1.a; > insert into t1(a,b) values(2, 5); > explain cbo alter materialized view mat1 rebuild; > {code} > {code} > java.lang.AssertionError: > Cannot add expression of different type to set: > set type is RecordType(INTEGER $f0, DECIMAL(17, 2) $f1) NOT NULL > expression type is RecordType(INTEGER $f0, DECIMAL(18, 2) $f1) NOT NULL > set is > rel#388:HiveAggregate.HIVE.[].any(input=HepRelVertex#387,group={0},agg#0=sum($1)) > expression is HiveProject($f0=[$3], $f1=[CASE(IS NULL($1), $4, IS NULL($4), > $1, +($4, $1))]) > HiveFilter(condition=[OR($2, IS NULL($2))]) > HiveJoin(condition=[IS NOT DISTINCT FROM($0, $3)], joinType=[right], > algorithm=[none], cost=[not available]) > HiveProject(a=[$0], _c1=[$1], $f2=[true]) > HiveTableScan(table=[[default, mat1]], table:alias=[default.mat1]) > HiveAggregate(group=[{0}], agg#0=[sum($1)]) > HiveProject($f0=[$0], $f1=[$1]) > HiveFilter(condition=[<(1, $4.writeid)]) > HiveTableScan(table=[[default, t1]], table:alias=[t1]) > at > org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:380) > at > org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:58) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:268) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:283) > at > org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveAggregateIncrementalRewritingRuleBase.onMatch(HiveAggregateIncrementalRewritingRuleBase.java:161) > at > org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:333) > at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:542) > at > org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:407) > at > org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:243) > at > org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:127) > at > org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:202) > at > org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:189) > at > org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.executeProgram(CalcitePlanner.java:2468) > at > org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.executeProgram(CalcitePlanner.java:2427) > at > org.apache.hadoop.hive.ql.ddl.view.materialized.alter.rebuild.AlterMaterializedViewRebuildAnalyzer$MVRebuildCalcitePlannerAction.applyIncrementalRebuild(AlterMaterializedViewRebuildAnalyzer.java:460) > at > org.apache.hadoop.hive.ql.ddl.view.materialized.alter.rebuild.AlterMaterializedViewRebuildAnalyzer$MVRebuildCalcitePlannerAction.applyAggregateInsertIncremental(AlterMaterializedViewRebuildAnalyzer.java:352) > at > org.apache.hadoop.hive.ql.ddl.view.materialized.alter.rebuild.AlterMaterializedViewRebuildAnalyzer$MVRebuildCalcitePlannerAction.applyRecordIncrementalRebuildPlan(AlterMaterializedViewRebuildAnalyzer.java:311) > at > org.apache.hadoop.hive.ql.ddl.view.materialized.alter.rebuild.AlterMaterializedViewRebuildAnalyzer$MVRebuildCalcitePlannerAction.applyMaterializedViewRewriting(AlterM
[jira] [Work logged] (HIVE-27305) AssertionError in Calcite during planning for incremental rebuild of materialized view with aggregate on decimal column
[ https://issues.apache.org/jira/browse/HIVE-27305?focusedWorklogId=860109&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-860109 ] ASF GitHub Bot logged work on HIVE-27305: - Author: ASF GitHub Bot Created on: 02/May/23 13:56 Start Date: 02/May/23 13:56 Worklog Time Spent: 10m Work Description: amansinha100 commented on code in PR #4277: URL: https://github.com/apache/hive/pull/4277#discussion_r1182586454 ## ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveAggregateIncrementalRewritingRuleBase.java: ## @@ -142,10 +142,13 @@ public void onMatch(RelOptRuleCall call) { // Note: If both are null, we will fall into branchWHEN leftNull THEN rightRef RexNode leftNull = rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, leftRef); RexNode rightNull = rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, rightRef); - projExprs.add(rexBuilder.makeCall(SqlStdOperatorTable.CASE, + RexNode caseExpression = rexBuilder.makeCall(SqlStdOperatorTable.CASE, leftNull, rightRef, rightNull, leftRef, - elseReturn)); + elseReturn); + RexNode cast = rexBuilder.makeCast( Review Comment: Ok, so the extra cast gets removed later .. thanks for checking, Issue Time Tracking --- Worklog Id: (was: 860109) Time Spent: 50m (was: 40m) > AssertionError in Calcite during planning for incremental rebuild of > materialized view with aggregate on decimal column > --- > > Key: HIVE-27305 > URL: https://issues.apache.org/jira/browse/HIVE-27305 > Project: Hive > Issue Type: Bug > Components: CBO, Materialized views >Reporter: Krisztian Kasa >Assignee: Krisztian Kasa >Priority: Major > Labels: pull-request-available > Time Spent: 50m > Remaining Estimate: 0h > > {code} > set hive.support.concurrency=true; > set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; > set hive.materializedview.rewriting.sql=false; > create table t1(a int, b decimal(7,2)) stored as orc TBLPROPERTIES > ('transactional'='true'); > insert into t1(a, b) values(1, 1); > create materialized view mat1 stored as orc TBLPROPERTIES > ('transactional'='true') as > select t1.a, sum(t1.b) from t1 > group by t1.a; > insert into t1(a,b) values(2, 5); > explain cbo alter materialized view mat1 rebuild; > {code} > {code} > java.lang.AssertionError: > Cannot add expression of different type to set: > set type is RecordType(INTEGER $f0, DECIMAL(17, 2) $f1) NOT NULL > expression type is RecordType(INTEGER $f0, DECIMAL(18, 2) $f1) NOT NULL > set is > rel#388:HiveAggregate.HIVE.[].any(input=HepRelVertex#387,group={0},agg#0=sum($1)) > expression is HiveProject($f0=[$3], $f1=[CASE(IS NULL($1), $4, IS NULL($4), > $1, +($4, $1))]) > HiveFilter(condition=[OR($2, IS NULL($2))]) > HiveJoin(condition=[IS NOT DISTINCT FROM($0, $3)], joinType=[right], > algorithm=[none], cost=[not available]) > HiveProject(a=[$0], _c1=[$1], $f2=[true]) > HiveTableScan(table=[[default, mat1]], table:alias=[default.mat1]) > HiveAggregate(group=[{0}], agg#0=[sum($1)]) > HiveProject($f0=[$0], $f1=[$1]) > HiveFilter(condition=[<(1, $4.writeid)]) > HiveTableScan(table=[[default, t1]], table:alias=[t1]) > at > org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:380) > at > org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:58) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:268) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:283) > at > org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveAggregateIncrementalRewritingRuleBase.onMatch(HiveAggregateIncrementalRewritingRuleBase.java:161) > at > org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:333) > at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:542) > at > org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:407) > at > org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:243) > at > org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:127) > at > org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:202) > at > org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:189) > at > org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.executeProgram(CalcitePlanner.java:2468) > at > org.apache.hadoop.hive.ql.parse.Calc
[jira] [Work logged] (HIVE-27305) AssertionError in Calcite during planning for incremental rebuild of materialized view with aggregate on decimal column
[ https://issues.apache.org/jira/browse/HIVE-27305?focusedWorklogId=859987&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-859987 ] ASF GitHub Bot logged work on HIVE-27305: - Author: ASF GitHub Bot Created on: 02/May/23 08:14 Start Date: 02/May/23 08:14 Worklog Time Spent: 10m Work Description: kasakrisz commented on code in PR #4277: URL: https://github.com/apache/hive/pull/4277#discussion_r1182227739 ## ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveAggregateIncrementalRewritingRuleBase.java: ## @@ -142,10 +142,13 @@ public void onMatch(RelOptRuleCall call) { // Note: If both are null, we will fall into branchWHEN leftNull THEN rightRef RexNode leftNull = rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, leftRef); RexNode rightNull = rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, rightRef); - projExprs.add(rexBuilder.makeCall(SqlStdOperatorTable.CASE, + RexNode caseExpression = rexBuilder.makeCall(SqlStdOperatorTable.CASE, leftNull, rightRef, rightNull, leftRef, - elseReturn)); + elseReturn); + RexNode cast = rexBuilder.makeCast( Review Comment: Yes, but expressions are simplified when added to `Project` https://github.com/apache/calcite/blob/68b02dfd4af15bc94a91a0cd2a30655d04439555/core/src/main/java/org/apache/calcite/tools/RelBuilder.java#L1415 When source and destination types are equal this simplification removes the cast. The MV rebuild CBO plan in `materialized_view_create_rewrite_6.q.out` shows that only the decimal type aggregates has cast. ``` HiveProject( a=[$5], _o__c1=[CAST(CASE(IS NULL($1), $6, +($6, $1))):DECIMAL(17, 2)], _o__c2=[CASE(IS NULL($2), $7, +($7, $2))], _o__c3=[CAST(/(CAST(CASE(IS NULL($1), $6, +($6, $1))):DECIMAL(17, 2), CASE(IS NULL($2), $7, +($7, $2:DECIMAL(11, 6)], _o__c4=[CASE(IS NULL($3), $8, +($8, $3))]) ``` Issue Time Tracking --- Worklog Id: (was: 859987) Time Spent: 40m (was: 0.5h) > AssertionError in Calcite during planning for incremental rebuild of > materialized view with aggregate on decimal column > --- > > Key: HIVE-27305 > URL: https://issues.apache.org/jira/browse/HIVE-27305 > Project: Hive > Issue Type: Bug > Components: CBO, Materialized views >Reporter: Krisztian Kasa >Assignee: Krisztian Kasa >Priority: Major > Labels: pull-request-available > Time Spent: 40m > Remaining Estimate: 0h > > {code} > set hive.support.concurrency=true; > set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; > set hive.materializedview.rewriting.sql=false; > create table t1(a int, b decimal(7,2)) stored as orc TBLPROPERTIES > ('transactional'='true'); > insert into t1(a, b) values(1, 1); > create materialized view mat1 stored as orc TBLPROPERTIES > ('transactional'='true') as > select t1.a, sum(t1.b) from t1 > group by t1.a; > insert into t1(a,b) values(2, 5); > explain cbo alter materialized view mat1 rebuild; > {code} > {code} > java.lang.AssertionError: > Cannot add expression of different type to set: > set type is RecordType(INTEGER $f0, DECIMAL(17, 2) $f1) NOT NULL > expression type is RecordType(INTEGER $f0, DECIMAL(18, 2) $f1) NOT NULL > set is > rel#388:HiveAggregate.HIVE.[].any(input=HepRelVertex#387,group={0},agg#0=sum($1)) > expression is HiveProject($f0=[$3], $f1=[CASE(IS NULL($1), $4, IS NULL($4), > $1, +($4, $1))]) > HiveFilter(condition=[OR($2, IS NULL($2))]) > HiveJoin(condition=[IS NOT DISTINCT FROM($0, $3)], joinType=[right], > algorithm=[none], cost=[not available]) > HiveProject(a=[$0], _c1=[$1], $f2=[true]) > HiveTableScan(table=[[default, mat1]], table:alias=[default.mat1]) > HiveAggregate(group=[{0}], agg#0=[sum($1)]) > HiveProject($f0=[$0], $f1=[$1]) > HiveFilter(condition=[<(1, $4.writeid)]) > HiveTableScan(table=[[default, t1]], table:alias=[t1]) > at > org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:380) > at > org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:58) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:268) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:283) > at > org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveAggregateIncrementalRewritingRuleBase.onMatch(HiveAggregateIncrementalRewritingRuleBase.java:161) > at > org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:333) >
[jira] [Work logged] (HIVE-27305) AssertionError in Calcite during planning for incremental rebuild of materialized view with aggregate on decimal column
[ https://issues.apache.org/jira/browse/HIVE-27305?focusedWorklogId=859802&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-859802 ] ASF GitHub Bot logged work on HIVE-27305: - Author: ASF GitHub Bot Created on: 29/Apr/23 18:34 Start Date: 29/Apr/23 18:34 Worklog Time Spent: 10m Work Description: amansinha100 commented on code in PR #4277: URL: https://github.com/apache/hive/pull/4277#discussion_r1181113249 ## ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveAggregateIncrementalRewritingRuleBase.java: ## @@ -142,10 +142,13 @@ public void onMatch(RelOptRuleCall call) { // Note: If both are null, we will fall into branchWHEN leftNull THEN rightRef RexNode leftNull = rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, leftRef); RexNode rightNull = rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, rightRef); - projExprs.add(rexBuilder.makeCall(SqlStdOperatorTable.CASE, + RexNode caseExpression = rexBuilder.makeCall(SqlStdOperatorTable.CASE, leftNull, rightRef, rightNull, leftRef, - elseReturn)); + elseReturn); + RexNode cast = rexBuilder.makeCast( Review Comment: Will this introduce a CAST even when the CAST was not needed ? Issue Time Tracking --- Worklog Id: (was: 859802) Time Spent: 0.5h (was: 20m) > AssertionError in Calcite during planning for incremental rebuild of > materialized view with aggregate on decimal column > --- > > Key: HIVE-27305 > URL: https://issues.apache.org/jira/browse/HIVE-27305 > Project: Hive > Issue Type: Bug > Components: CBO, Materialized views >Reporter: Krisztian Kasa >Assignee: Krisztian Kasa >Priority: Major > Labels: pull-request-available > Time Spent: 0.5h > Remaining Estimate: 0h > > {code} > set hive.support.concurrency=true; > set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; > set hive.materializedview.rewriting.sql=false; > create table t1(a int, b decimal(7,2)) stored as orc TBLPROPERTIES > ('transactional'='true'); > insert into t1(a, b) values(1, 1); > create materialized view mat1 stored as orc TBLPROPERTIES > ('transactional'='true') as > select t1.a, sum(t1.b) from t1 > group by t1.a; > insert into t1(a,b) values(2, 5); > explain cbo alter materialized view mat1 rebuild; > {code} > {code} > java.lang.AssertionError: > Cannot add expression of different type to set: > set type is RecordType(INTEGER $f0, DECIMAL(17, 2) $f1) NOT NULL > expression type is RecordType(INTEGER $f0, DECIMAL(18, 2) $f1) NOT NULL > set is > rel#388:HiveAggregate.HIVE.[].any(input=HepRelVertex#387,group={0},agg#0=sum($1)) > expression is HiveProject($f0=[$3], $f1=[CASE(IS NULL($1), $4, IS NULL($4), > $1, +($4, $1))]) > HiveFilter(condition=[OR($2, IS NULL($2))]) > HiveJoin(condition=[IS NOT DISTINCT FROM($0, $3)], joinType=[right], > algorithm=[none], cost=[not available]) > HiveProject(a=[$0], _c1=[$1], $f2=[true]) > HiveTableScan(table=[[default, mat1]], table:alias=[default.mat1]) > HiveAggregate(group=[{0}], agg#0=[sum($1)]) > HiveProject($f0=[$0], $f1=[$1]) > HiveFilter(condition=[<(1, $4.writeid)]) > HiveTableScan(table=[[default, t1]], table:alias=[t1]) > at > org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:380) > at > org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:58) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:268) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:283) > at > org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveAggregateIncrementalRewritingRuleBase.onMatch(HiveAggregateIncrementalRewritingRuleBase.java:161) > at > org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:333) > at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:542) > at > org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:407) > at > org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:243) > at > org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:127) > at > org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:202) > at > org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:189) > at > org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.executeProgram(CalcitePlanner.java:2468) > at > org.apache.hadoop.hive.ql.parse.Calc