rubenada commented on code in PR #6495:
URL: https://github.com/apache/hive/pull/6495#discussion_r3267134245


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/type/HiveFunctionHelper.java:
##########
@@ -267,27 +267,19 @@ public RexNode getExpression(String functionText, 
FunctionInfo fi,
         // If it is a floor <date> operator, we need to rewrite it
         inputs = RexNodeConverter.rewriteFloorDateChildren(calciteOp, inputs, 
rexBuilder);
       } else if (HiveIn.INSTANCE.equals(calciteOp)) {
-        // if it is a single item in an IN clause, transform A IN (B) to A = B
-        // from IN [A,B] => EQUALS [A,B]
-        // if it is more than an single item in an IN clause,
-        // transform from IN [A,B,C] => OR [EQUALS [A,B], EQUALS [A,C]]
-        // Rewrite to OR is done only if number of operands are less than
-        // the threshold configured
-        boolean rewriteToOr = true;
-        if(maxNodesForInToOrTransformation != 0) {
-          if(inputs.size() > maxNodesForInToOrTransformation) {
-            rewriteToOr = false;
-          }
-        }
-        if(rewriteToOr) {
-          // If there are non-deterministic functions, we cannot perform this 
rewriting
-          List<RexNode> newInputs = 
RexNodeConverter.transformInToOrOperands(inputs, rexBuilder);
-          if (newInputs != null) {
-            inputs = newInputs;
-            if (inputs.size() == 1) {
-              inputs.add(rexBuilder.makeLiteral(false));
+        RexNode rewritten = RexNodeConverter.rewriteInClause(inputs, 
rexBuilder);
+        if (rewritten != null) {
+          assert rewritten instanceof RexCall;
+          RexCall call = (RexCall) rewritten;
+          if (call.getKind() == SqlKind.OR && maxNodesForInToOrTransformation 
!= 0) {
+            // Rewrite to OR is done only if number of operands are less than 
the threshold configured
+            if (call.getOperands().size() <= maxNodesForInToOrTransformation) {

Review Comment:
   I agree, I'll try to move this logic into RexNodeConverter (makes more sense 
in there), to perform the check before actually generating the OR. 
   I guess we should keep this "maxnodes check" since this property was 
introduced due to perf issues (HIVE-22074: Slow compilation due to IN to OR 
transformation)



-- 
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]

Reply via email to