Skip to content

HIVE-29447: Incorrect nullability inference when transforming SEARCH expression back to disjunctions#6318

Draft
kasakrisz wants to merge 1 commit intoapache:masterfrom
kasakrisz:HIVE-29447-master-search-notnull
Draft

HIVE-29447: Incorrect nullability inference when transforming SEARCH expression back to disjunctions#6318
kasakrisz wants to merge 1 commit intoapache:masterfrom
kasakrisz:HIVE-29447-master-search-notnull

Conversation

@kasakrisz
Copy link
Contributor

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

mvn test -Dtest.output.overwrite -Dtest=TestMiniLlapLocalCliDriver -Dqfile=cbo_search.q -pl itests/qtest -Pitests

@kasakrisz kasakrisz force-pushed the HIVE-29447-master-search-notnull branch from f283076 to 52a3d70 Compare February 17, 2026 15:51
@kasakrisz kasakrisz marked this pull request as draft February 17, 2026 15:51
@sonarqubecloud
Copy link

@soumyakanti3578
Copy link
Contributor

soumyakanti3578 commented Feb 17, 2026

@kasakrisz
From the failed tests, it looks like CAST would not pass the Filter litmus test, as seen in the test failure: materialized_view_rewrite_in_between.q.

How about just creating a new RexCall with the type of the search, since we want the new expression to have the same type as the SEARCH? I tried a few failing tests with this change and they all passed.

--- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/SearchTransformer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/SearchTransformer.java
@@ -59,22 +59,24 @@ public class SearchTransformer<C extends Comparable<C>> {
   private final RexNode ref;
   private final Sarg<C> sarg;
   private final RexUnknownAs unknownContext;
-  protected final RelDataType type;
+  protected final RelDataType operandType;
+  private final RelDataType expressionType;

   public SearchTransformer(RexBuilder rexBuilder, RexCall search, final RexUnknownAs unknownContext) {
     this.rexBuilder = rexBuilder;
     ref = search.getOperands().get(0);
     RexLiteral literal = (RexLiteral) search.operands.get(1);
     sarg = Objects.requireNonNull(literal.getValueAs(Sarg.class), "Sarg");
-    type = literal.getType();
+    operandType = literal.getType();
     this.unknownContext = unknownContext;
+    this.expressionType = search.getType();
   }

   public RexNode transform() {
     PerfLogger perfLogger = SessionState.getPerfLogger();
     perfLogger.perfLogBegin(this.getClass().getName(), PerfLogger.SEARCH_TRANSFORMER);

-    RangeConverter<C> consumer = new RangeConverter<>(rexBuilder, type, ref);
+    RangeConverter<C> consumer = new RangeConverter<>(rexBuilder, operandType, ref);
     RangeSets.forEach(sarg.rangeSet, consumer);

     List<RexNode> orList = new ArrayList<>();
@@ -101,6 +103,11 @@ public RexNode transform() {
       x = RexUtil.composeConjunction(rexBuilder, Arrays.asList(notNull, x));
     }
     perfLogger.perfLogEnd(this.getClass().getName(), PerfLogger.SEARCH_TRANSFORMER);
+
+    if (!expressionType.equals(x.getType())) {
+      x = rexBuilder.makeCall(expressionType, ((RexCall) x).getOperator(), ((RexCall) x).getOperands());
+    }
+
     return x;
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants