dawidwys commented on code in PR #24704:
URL: https://github.com/apache/flink/pull/24704#discussion_r1609956392


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/SqlJsonQueryFunctionWrapper.java:
##########
@@ -30,23 +39,67 @@
  * VARCHAR_FORCE_NULLABLE} return type inference.
  */
 class SqlJsonQueryFunctionWrapper extends SqlJsonQueryFunction {
+    private final SqlReturnTypeInference returnTypeInference;
+
+    SqlJsonQueryFunctionWrapper() {
+        this.returnTypeInference =
+                ReturnTypes.cascade(
+                                SqlJsonQueryFunctionWrapper::explicitTypeSpec,
+                                SqlTypeTransforms.FORCE_NULLABLE)
+                        .orElse(VARCHAR_FORCE_NULLABLE);
+    }
 
     @Override
     public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
-        RelDataType returnType = 
VARCHAR_FORCE_NULLABLE.inferReturnType(opBinding);
+        RelDataType returnType = 
returnTypeInference.inferReturnType(opBinding);
         if (returnType == null) {
             throw new IllegalArgumentException(
                     "Cannot infer return type for "
                             + opBinding.getOperator()
                             + "; operand types: "
                             + opBinding.collectOperandTypes());
-        } else {
-            return returnType;
         }
+        return returnType;
     }
 
     @Override
     public SqlReturnTypeInference getReturnTypeInference() {
-        return VARCHAR_FORCE_NULLABLE;
+        return returnTypeInference;
+    }
+
+    @Override
+    public boolean checkOperandTypes(SqlCallBinding callBinding, boolean 
throwOnFailure) {
+        if (!super.checkOperandTypes(callBinding, throwOnFailure)) {
+            return false;
+        }
+
+        if (callBinding.getOperandCount() >= 6) {
+            final RelDataType type = SqlTypeUtil.deriveType(callBinding, 
callBinding.operand(5));
+            if (SqlTypeUtil.isArray(type) && 
!SqlTypeUtil.isCharacter(type.getComponentType())) {
+                if (throwOnFailure) {
+                    throw new ValidationException(
+                            String.format(
+                                    "Unsupported array element type '%s' for 
RETURNING ARRAY in JSON_QUERY().",

Review Comment:
   Yes, but the exception comes from Calcite. We don't overwrite all Calcite's 
messages :(
   
   I am sure we will have collection types rendered that way at many other 
places.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to