clintropolis commented on code in PR #15609:
URL: https://github.com/apache/druid/pull/15609#discussion_r1441022060
##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/SearchOperatorConversion.java:
##########
@@ -83,7 +97,187 @@
return Expressions.toDruidExpression(
plannerContext,
rowSignature,
- RexUtil.expandSearch(REX_BUILDER, null, rexNode)
+ expandSearch((RexCall) rexNode, REX_BUILDER)
);
}
+
+ /**
+ * Like {@link RexUtil#expandSearch(RexBuilder, RexProgram, RexNode)}, but
with some enhancements:
+ *
+ * 1) Expands NOT IN (a.k.a. {@link Sarg#isComplementedPoints()} as !(a || b
|| c) rather than (!a && !b && !c),
+ * which helps us convert it to an {@link InDimFilter} later.
+ *
+ * 2) Can generate nice conversions for complement-points even if the range
is not *entirely* complement-points.
+ */
+ public static RexNode expandSearch(
+ final RexCall call,
+ final RexBuilder rexBuilder
+ )
+ {
+ final RexNode arg = call.operands.get(0);
+ final RexLiteral sargRex = (RexLiteral) call.operands.get(1);
+ final Sarg<?> sarg = sargRex.getValueAs(Sarg.class);
+
+ if (sarg.isAll() || sarg.isNone()) {
+ return RexUtil.expandSearch(rexBuilder, null, call);
+ }
+
+ // RexNodes that represent ranges *including* the notInPoints. Later, the
notInRexNode will be ANDed in so
+ // those notInPoints can be removed.
+ final List<RexNode> rangeRexNodes = new ArrayList<>();
+
+ // Compute points that occur in the complement of the range set. These are
"NOT IN" points.
+ final List<Comparable> notInPoints;
+ final List<RexNode> notInRexNodes;
Review Comment:
this seems true, what is it for?
##########
sql/src/main/java/org/apache/druid/sql/calcite/filtration/CollectComparisons.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.sql.calcite.filtration;
+
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import it.unimi.dsi.fastutil.objects.ObjectIntPair;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.query.filter.InDimFilter;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Utility class for collecting point comparisons that are children to an OR,
such as equalities. Each set of
+ * comparisons with the same {@link CollectionKey} can potentially become a
single {@link CollectedType}.
+ * For example: x = 'a', x = 'b' can become x IN ('a', 'b').
+ */
+public abstract class CollectComparisons<ExprType, ComparisonType extends
ExprType, CollectedType extends ExprType, CollectionKey>
Review Comment:
nit: `ExprType` is kind of confusing since there is a real `ExprType`, maybe
`BaseType` or `CommonType` would be better?
--
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]