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/06/05 03:05:39 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_r889640250


##########
core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java:
##########
@@ -205,6 +207,12 @@ public static SqlIntervalLiteral parseIntervalLiteral(SqlParserPos pos,
     return SqlLiteral.createInterval(sign, intervalStr, intervalQualifier, pos);
   }
 
+  public static SqlNode parseArrayLiteral(String s) throws Exception {

Review Comment:
   Needs a javadoc comment. Especially the fact that you use the default parser.



##########
core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties:
##########
@@ -319,4 +319,5 @@ InvalidInputForExtractXml=Invalid input for EXTRACT xpath: ''{0}'', namespace: '
 InvalidInputForExistsNode=Invalid input for EXISTSNODE xpath: ''{0}'', namespace: ''{1}''
 DifferentLengthForBitwiseOperands=Different length for bitwise operands: the first: {0,number,#}, the second: {1,number,#}
 NoOperator=No operator for ''{0}'' with kind: ''{1}'', syntax: ''{2}'' during JSON deserialization
+IllegalArrayExpression=Illegal array expression {0}

Review Comment:
   please put the line in the correct place in the file; putting it at the end tends to create merge conflicts



##########
core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java:
##########
@@ -547,6 +547,11 @@ protected SqlCall createCall(
    */
   public abstract void setConformance(SqlConformance conformance);
 
+  /**
+   * Parse string to array literal.

Review Comment:
   should be 'Parses a string to an array literal'



##########
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:
   catch Throwable is not Ok



##########
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
+    ) {

Review Comment:
   ')' should be at end of line



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