liyafan82 commented on a change in pull request #2233:
URL: https://github.com/apache/calcite/pull/2233#discussion_r513968933
##########
File path: core/src/main/java/org/apache/calcite/rex/RexUtil.java
##########
@@ -565,32 +565,36 @@ public static RexFinder find(final RexInputRef ref) {
};
}
+ /** Expands calls to {@link SqlStdOperatorTable#SEARCH} in an expression. */
public static RexNode expandSearch(RexBuilder rexBuilder,
@Nullable RexProgram program, RexNode node) {
- final RexShuttle shuttle = new RexShuttle() {
- @Override public RexNode visitCall(RexCall call) {
- switch (call.getKind()) {
- case SEARCH:
- return visitSearch(rexBuilder, program, call);
- default:
- return super.visitCall(call);
- }
- }
- };
- return node.accept(shuttle);
+ return node.accept(searchShuttle(rexBuilder, program, -1));
+ }
+
+ /** Creates a shuttle that expands calls to
+ * {@link SqlStdOperatorTable#SEARCH}.
+ *
+ * <p>If {@code maxComplexity} is non-negative, a {@link Sarg} whose
+ * complexity is greater than {@code maxComplexity} is retained (not
+ * expanded); this gives a means to simplify simple expressions such as
+ * {@code x IS NULL} or {@code x > 10} while keeping more complex expressions
+ * such as {@code x IN (3, 5, 7) OR x IS NULL} as a Sarg. */
+ public static RexShuttle searchShuttle(RexBuilder rexBuilder,
+ RexProgram program, int maxComplexity) {
+ return new SearchExpandingShuttle(program, rexBuilder, maxComplexity);
}
@SuppressWarnings("BetaApi")
- private static <C extends Comparable<C>> RexNode
- visitSearch(RexBuilder rexBuilder,
- @Nullable RexProgram program, RexCall call) {
- final RexNode ref = call.operands.get(0);
- final RexLiteral literal =
- (RexLiteral) deref(program, call.operands.get(1));
- @SuppressWarnings("unchecked")
- final Sarg<C> sarg = literal.getValueAs(Sarg.class);
+ private static <C extends Comparable<C>> RexNode sargRef(
+ RexBuilder rexBuilder, RexNode ref, Sarg<C> sarg, RelDataType type) {
+ if (sarg.isAll()) {
+ if (sarg.containsNull) {
Review comment:
Here we can extend the condition to be `sarg.containsNull ||
!type.isNullable()`?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]