You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/10/20 18:41:02 UTC

[GitHub] [calcite] julianhyde commented on a diff in pull request #2819: [CALCITE-5159] Postgres dialect should support implicit cast from string literal to array literal

julianhyde commented on code in PR #2819:
URL: https://github.com/apache/calcite/pull/2819#discussion_r1000994647


##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java:
##########
@@ -721,4 +738,31 @@ boolean canImplicitTypeCast(List<RelDataType> types, List<SqlTypeFamily> familie
     }
     return null;
   }
+
+  /**
+   * Coerce STRING type to ARRAY type.
+   */
+  protected Boolean coerceStringToArray(
+      SqlCall call,
+      SqlNode operand,
+      int index,
+      RelDataType fromType,
+      RelDataType targetType) {
+    if (validator.config().conformance().allowCoercionStringToArray()
+        && SqlTypeUtil.isString(fromType)
+        && SqlTypeUtil.isArray(targetType)
+        && operand instanceof SqlCharStringLiteral
+    ) {
+      try {
+        SqlNode arrayValue = SqlParserUtil.parseArrayLiteral(
+            ((SqlCharStringLiteral) operand).getValueAs(String.class));
+        call.setOperand(index, arrayValue);
+        updateInferredType(arrayValue, targetType);
+      } catch (Throwable e) {
+        return false;

Review Comment:
   Yes, `catch Error` is just as bad as `catch Throwable`.
   
   Is it possible for `parseArrayLiteral` to declare a short list of exceptions that it may throw? Some of them will be user errors (i.e. the string is not valid format); internal errors (e.g. `NullPointerException`, `ArrayIndexOutOfBoundsException`) should be rethrown, not become `return false`.



-- 
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: commits-unsubscribe@calcite.apache.org

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