snuyanzin commented on code in PR #24704:
URL: https://github.com/apache/flink/pull/24704#discussion_r1609901436
##########
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:
This is probably the result of difference in collection parsing between
Flink and Calcite
For Flink we have `ARRAY<STRING>`
in Calcite this syntax with angle brackets is not supported and it will be
something like `VARCHAR ARRAY`
Thus from Calcite's point of view syntax is ok since it is supported in
Calcite, however in Flink it is a bit different
--
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]