chucheng92 commented on code in PR #3579:
URL: https://github.com/apache/calcite/pull/3579#discussion_r1427504943
##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -1225,6 +1229,64 @@ private static class MapFromEntriesOperandTypeChecker
}
}
+ /**
+ * Operand type-checking strategy for a ARRAY function, it allows empty
array.
+ *
+ * <p> The reason it overrides SameOperandTypeChecker#checkOperandTypesImpl
is that it needs
+ * to handle the scenario where row/struct type and NULL exist
simultaneously in array.
+ * This scenario need be supported, but will be rejected by the current
checkOperandTypesImpl.
+ */
+ private static class ArrayFunctionOperandTypeChecker
+ extends SameOperandTypeChecker {
+
+ ArrayFunctionOperandTypeChecker() {
+ // The args of array are non-fixed, so we set to -1 here. then
operandCount
+ // can dynamically set according to the number of input args.
+ // details please see SameOperandTypeChecker#getOperandList.
+ super(-1);
+ }
+
+ @Override protected boolean checkOperandTypesImpl(
+ SqlOperatorBinding operatorBinding,
+ boolean throwOnFailure,
+ @Nullable SqlCallBinding callBinding) {
+ if (throwOnFailure && callBinding == null) {
+ throw new IllegalArgumentException(
+ "callBinding must be non-null in case throwOnFailure=true");
+ }
+ int nOperandsActual = nOperands;
+ if (nOperandsActual == -1) {
+ nOperandsActual = operatorBinding.getOperandCount();
+ }
+ RelDataType[] types = new RelDataType[nOperandsActual];
+ final List<Integer> operandList =
+ getOperandList(operatorBinding.getOperandCount());
+ for (int i : operandList) {
+ types[i] = operatorBinding.getOperandType(i);
+ }
+ int prev = -1;
+ for (int i : operandList) {
+ if (prev >= 0) {
Review Comment:
yes, we use `prev` to record previous index. but can also use `i` directly.
updated the PR.
--
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]