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


##########
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:
   One nice to have comment: not sure how easy to fix it
   It looks like here the output of component type is different from Flink SQL 
syntax
   for instance for this query
   ```sql
   SELECT JSON_QUERY('{"a":[{"c":"c1"},{"c":"c2"}]}', 'lax $.a[*].c' RETURNING 
ARRAY<MAP<INTEGER, STRING>>);
   ```
   I would expect something like 
   
   > Unsupported array element type 'MAP<INTEGER, STRING>' for RETURNING ARRAY 
in JSON_QUERY().
   
   however the actual message 
   is
   >Unsupported array element type '(INTEGER, VARCHAR(2147483647)) MAP' for 
RETURNING ARRAY in JSON_QUERY().
   
   anyway, i think it only nice to have



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