bchapuis commented on code in PR #2854:
URL: https://github.com/apache/calcite/pull/2854#discussion_r1126983623
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -4049,6 +4081,99 @@ private static class HopImplementor implements
TableFunctionCallImplementor {
}
}
+ /**
+ * Implements
+ * <a
href="https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.30.16">
+ * ANY/SOME</a> and
+ * <a
href="https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.30.17">ALL</a>
+ * operators when the argument is an array or multiset expression.
+ */
+ private static class QuantifyCollectionImplementor extends
AbstractRexCallImplementor {
+ private final SqlBinaryOperator binaryOperator;
+ private final RexCallImplementor binaryImplementor;
+
+ QuantifyCollectionImplementor(SqlBinaryOperator binaryOperator,
+ RexCallImplementor binaryImplementor) {
+ super(NullPolicy.ANY, false);
+ this.binaryOperator = binaryOperator;
+ this.binaryImplementor = binaryImplementor;
+ }
+
+ @Override String getVariableName() {
+ return "quantify";
+ }
+
+ @Override Expression implementSafe(RexToLixTranslator translator, RexCall
call,
+ List<Expression> argValueList) {
+ Expression left = argValueList.get(0);
+ Expression right = argValueList.get(1);
+ final RelDataType rightComponentType =
+
requireNonNull(call.getOperands().get(1).getType().getComponentType());
+ // If the array expression yields a null array, the result of SOME|ALL
will be null
+ if (rightComponentType.getSqlTypeName() == SqlTypeName.NULL) {
+ return NULL_EXPR;
+ }
+
+ // final T _quantify_left_value = <>
Review Comment:
To me, it is not obvious why the following lines are commented.
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -3636,6 +3636,44 @@ public static Object[] array(Object... args) {
return args;
}
+ /**
+ * Returns whether there is an element in {@code list} for which {@code
predicate} is true.
+ * Also, if {@code predicate} returns null for any element of {@code list}
+ * and there are no true comparison result is obtained, the result will be
null, not false.
Review Comment:
This sentence should probably be reworked (i.e. "there are" and "is
obtained").
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -130,27 +133,22 @@
/**
* Contains unit tests for all operators. Each of the methods is named after an
* operator.
- *
Review Comment:
This file has probably been reformatted by the IDE.
##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -5451,7 +5461,11 @@ ImmutableList<RelNode> retrieveCursors() {
case CURSOR:
case IN:
case NOT_IN:
- subQuery = requireNonNull(getSubQuery(expr, null));
+ subQuery = getSubQuery(expr, null);
+ if (subQuery == null && (kind == SqlKind.SOME || kind == SqlKind.ALL))
{
+ break;
+ }
+ assert subQuery != null;
Review Comment:
This assert can probably be removed as requireNonNull is called right after.
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -3636,6 +3636,44 @@ public static Object[] array(Object... args) {
return args;
}
+ /**
+ * Returns whether there is an element in {@code list} for which {@code
predicate} is true.
+ * Also, if {@code predicate} returns null for any element of {@code list}
+ * and there are no true comparison result is obtained, the result will be
null, not false.
+ */
+ public static @Nullable <E> Boolean nullableExists(List<? extends E> list,
+ Function1<E, Boolean> predicate) {
+ boolean nullExists = false;
+ for (E e : list) {
+ Boolean res = predicate.apply(e);
+ if (res == null) {
+ nullExists = true;
+ } else if (res) {
+ return true;
+ }
+ }
+ return nullExists ? null : false;
+ }
+
+ /**
+ * Returns whether {@code predicate} is true for all elements of {@code
list}.
+ * Also, if {@code predicate} returns null for any element of {@code list}
+ * and there are no false comparison result is obtained, the result will be
null, not true.
Review Comment:
This sentence should probably be reworked (i.e. "there are" and "is
obtained").
--
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]