rubenada commented on code in PR #6477:
URL: https://github.com/apache/hive/pull/6477#discussion_r3264479940
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java:
##########
@@ -603,6 +605,151 @@ private Optional<Float> extractLiteral(SqlTypeName
typeName, Object boundValueOb
return Optional.of(value);
}
+ private double computeSearchSelectivity(RexCall search) {
+ return new SearchSelectivityHelper<>(search).compute();
+ }
+
+ /**
+ * Similar to {@link SearchTransformer}, but computing the selectivity of
the expression.
+ */
+ private final class SearchSelectivityHelper<C extends Comparable<C>> {
+ private final RexNode ref;
+ private final Sarg<C> sarg;
+ private final RelDataType operandType;
+
+ private SearchSelectivityHelper(RexCall search) {
+ ref = search.getOperands().get(0);
+ RexLiteral literal = (RexLiteral) search.operands.get(1);
+ sarg = Objects.requireNonNull(literal.getValueAs(Sarg.class), "Sarg");
+ operandType = literal.getType();
+ }
+
+ private RexNode makeLiteral(C value) {
+ return rexBuilder.makeLiteral(value, operandType, true, true);
+ }
+
+ private double compute() {
+ final List<Double> selectivityList = new ArrayList<>();
+ final List<RexNode> inLiterals = new ArrayList<>();
+
+ if (sarg.nullAs == RexUnknownAs.TRUE) {
+ selectivityList.add(
+ rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL,
ref).accept(FilterSelectivityEstimator.this));
+ }
+
+ RangeSets.forEach(sarg.rangeSet, new RangeSets.Consumer<C>() {
Review Comment:
I have no strong opinion here.
I agree that the original version with the `RangeSets.Consumer<C>` seemed a
bit better in terms of code homogeneity and maintainability (easier to find if
we ever need to apply adjustments to all rangeSet processing, like the
separate, incoming HIVE-28911).
So I'm willing to move back to the `Consumer` approach, wdyt @thomasrebele ?
--
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]