rubenada commented on code in PR #3237:
URL: https://github.com/apache/calcite/pull/3237#discussion_r1224478220


##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -471,6 +471,30 @@ public static SqlOperandTypeChecker variadic(
           .or(OperandTypes.family(SqlTypeFamily.MAP))
           .or(OperandTypes.family(SqlTypeFamily.ANY));
 
+  public static final SqlOperandTypeChecker 
STRING_OR_BINARY_ARRAY_STRING_OPTIONAL_STRING =
+      new FamilyOperandTypeChecker(
+          ImmutableList.of(SqlTypeFamily.ARRAY, SqlTypeFamily.STRING, 
SqlTypeFamily.STRING),
+          i -> i == 2) {
+        @SuppressWarnings("argument.type.incompatible")
+        @Override public boolean checkOperandTypes(
+            SqlCallBinding callBinding,
+            boolean throwOnFailure) {
+          if (!super.checkOperandTypes(callBinding, throwOnFailure)) {
+            return false;
+          }
+          RelDataType elementType = 
callBinding.getOperandType(0).getComponentType();
+          if (elementType == null || 
(!SqlTypeFamily.STRING.contains(elementType)
+              && !SqlTypeFamily.BINARY.contains(elementType))) {
+            if (throwOnFailure) {
+              throw callBinding.newValidationSignatureError();
+            }
+            return false;
+          }
+          return true;
+        }

Review Comment:
   To have a better validation error, I think we should also override the 
signature with something like:
   ```
           @Override public String getAllowedSignatures(SqlOperator op, String 
opName) {
             return opName + "(<STRING|BINARY ARRAY>, <STRING>[, <STRING>])";
           }
   ```
   Could you please try it? (and adjust the corresponding unit test accordingly)



-- 
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]

Reply via email to