soumyakanti3578 commented on code in PR #5196:
URL: https://github.com/apache/hive/pull/5196#discussion_r1938100955


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java:
##########
@@ -1078,6 +1098,36 @@ public ASTNode visitCall(RexCall call) {
         // proceed correctly if we just ignore the <time_unit>
         astNodeLst.add(call.operands.get(1).accept(this));
         break;
+      case SEARCH:
+        ASTNode astNode = call.getOperands().get(0).accept(this);
+        astNodeLst.add(astNode);
+        RexLiteral literal = (RexLiteral) call.operands.get(1);
+        Sarg<?> sarg = Objects.requireNonNull(literal.getValueAs(Sarg.class), 
"Sarg");
+        int minOrClauses = 
SessionState.getSessionConf().getIntVar(HiveConf.ConfVars.HIVE_POINT_LOOKUP_OPTIMIZER_MIN);
+
+        // convert Sarg to IN when they are points.
+        if (sarg.isPoints()) {
+          // just expand SEARCH to ORs when point count is less than 
HIVE_POINT_LOOKUP_OPTIMIZER_MIN
+          if (sarg.pointCount < minOrClauses) {
+            return visitCall((RexCall) 
call.accept(RexUtil.searchShuttle(rexBuilder, null, -1)));
+          }
+
+          // else convert to IN
+          for (Range<?> range : sarg.rangeSet.asRanges()) {
+            astNodeLst.add(visitLiteral((RexLiteral) rexBuilder.makeLiteral(
+                    range.lowerEndpoint(), literal.getType(), true, true)));
+          }
+          
+          return SqlFunctionConverter.buildAST(HiveIn.INSTANCE, astNodeLst, 
call.getType());
+          // Expand SEARCH operator
+        } else {
+          return visitCall((RexCall) transformOrToInAndInequalityToBetween(
+                  rexBuilder,
+                  call.accept(RexUtil.searchShuttle(rexBuilder, null, -1)),
+                  minOrClauses
+              )

Review Comment:
   Going through the commits in the PR, I found that I actually did try to 
generate `[NOT] BETWEEN` directly from `Sarg`s. But I later refactored to the 
use `transformOrToInAndInequalityToBetween` as I thought it was simpler, safer, 
and something that uses existing code.
   
   You can search for `between` in the commits to find the previous commits, 
especially please look into these (Not sharing links as they may change):
   1. Convert Sarg with bounded range to BETWEEN
   2. Ensure bound types for lower and upper endpoints are CLOSED to check ...
   3. Convert Sarg with multiple ranges to BETWEEN and NOT BETWEEN ...
   4. Use HivePointLookupOptimizerRule to convert SEARCH to BETWEEN ...
   
   Please let me know which one do you prefer. Maybe we could use just 
`RexTransformIntoBetween` to keep the code clean in ASTConverter, although I do 
understand that we have already paid in performance while converting to Sargs, 
and it would cost us again to expand the Sarg and use `RexTransformIntoBetween` 
to generate `[NOT] BETWEEN`. I can revert back to the previous commits if that 
is preferable. 



-- 
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: gitbox-unsubscr...@hive.apache.org

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


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

Reply via email to