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 branch WHEN 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))])
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]