mdayakar commented on code in PR #6895:
URL: https://github.com/apache/hive/pull/6895#discussion_r4327021732
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java:
##########
@@ -218,10 +218,14 @@ public ExprNodeDesc visitCall(RexCall call) {
return args.get(0);
} else if (call.isA(SqlKind.AND)) {
// Make sure AND is flattened (we may have nested ANDs due to
SearchTransformer conversion above)
- return ExprNodeDescUtils.and(args);
+ // Flattening/deduplication may collapse the operand list;
+ // AND require at least two operands (GenericUDFOPAnd#initialize
enforces this), so unwrapping trivial cases.
+ return unwrapSingleOperand(ExprNodeDescUtils.and(args));
} else if (call.isA(SqlKind.OR)) {
// Make sure OR is flattened (we may have nested ORs due to
SearchTransformer conversion above)
- return ExprNodeDescUtils.or(args);
+ // Flattening/deduplication may collapse the operand list;
+ // OR require at least two operands (GenericUDFOPOr#initialize enforces
this), so unwrapping trivial cases.
+ return unwrapSingleOperand(ExprNodeDescUtils.or(args));
Review Comment:
Here `ExprNodeDescUtils.or` and `ExprNodeDescUtils.and ` are returning
`ExprNodeGenericFuncDesc` so here we need to change the return type of these
functions to `ExprNodeDesc` which results in more changes so if required we can
do it in another PR. Also current `unwrapSingleOperand` API specific to AND/OR
functions so moving it to `ExprNodeDescUtils` requires more check so currently
not moving it.
##########
ql/src/test/queries/clientpositive/operands_deduplication.q:
##########
@@ -0,0 +1,4 @@
+create table mytable(id int, name string);
+
+explain select t1.id, t2.name, (case when (t1.id = 1 and t2.id = 1) then 'One'
else null end) mycase
Review Comment:
Added CBO
--
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]