This is an automated email from the ASF dual-hosted git repository.

yanlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new d8e5590  [CALCITE-4062] Support deserialize UDF array type from json 
string (Xu Zhaohui)
d8e5590 is described below

commit d8e559093f22ee5eefdee5758296efe3683d765b
Author: xzh <953396...@qq.com>
AuthorDate: Fri Jun 12 15:56:35 2020 +0800

    [CALCITE-4062] Support deserialize UDF array type from json string (Xu 
Zhaohui)
---
 .../org/apache/calcite/rel/externalize/RelJson.java  |  4 +++-
 .../java/org/apache/calcite/plan/RelWriterTest.java  | 18 ++++++++++++++++++
 .../apache/calcite/test/MockSqlOperatorTable.java    | 20 ++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java 
b/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java
index f4cb62a..2c9a0ca 100644
--- a/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java
+++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java
@@ -252,7 +252,9 @@ public class RelJson {
               new SqlIntervalQualifier(startUnit, endUnit, SqlParserPos.ZERO));
         }
         final RelDataType type;
-        if (precision == null) {
+        if (sqlTypeName == SqlTypeName.ARRAY) {
+          type = 
typeFactory.createArrayType(typeFactory.createSqlType(SqlTypeName.ANY), -1);
+        } else if (precision == null) {
           type = typeFactory.createSqlType(sqlTypeName);
         } else if (scale == null) {
           type = typeFactory.createSqlType(sqlTypeName, precision);
diff --git a/core/src/test/java/org/apache/calcite/plan/RelWriterTest.java 
b/core/src/test/java/org/apache/calcite/plan/RelWriterTest.java
index a564ddd..55a3d58 100644
--- a/core/src/test/java/org/apache/calcite/plan/RelWriterTest.java
+++ b/core/src/test/java/org/apache/calcite/plan/RelWriterTest.java
@@ -797,6 +797,24 @@ class RelWriterTest {
     assertThat(s, isLinux(expected));
   }
 
+  @Test void testArrayType() {
+    final FrameworkConfig config = RelBuilderTest.config().build();
+    final RelBuilder builder = RelBuilder.create(config);
+    final RelNode rel = builder
+        .scan("EMP")
+        .project(
+            builder.call(new MockSqlOperatorTable.SplitFunction(),
+                builder.field("ENAME"), builder.literal(",")))
+        .build();
+    final String relJson = RelOptUtil.dumpPlan("", rel,
+        SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
+    final String s = deserializeAndDumpToTextFormat(getSchema(rel), relJson);
+    final String expected = ""
+        + "LogicalProject($f0=[SPLIT($1, ',')])\n"
+        + "  LogicalTableScan(table=[[scott, EMP]])\n";
+    assertThat(s, isLinux(expected));
+  }
+
   /** Returns the schema of a {@link org.apache.calcite.rel.core.TableScan}
    * in this plan, or null if there are no scans. */
   private RelOptSchema getSchema(RelNode rel) {
diff --git 
a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java 
b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java
index 0ba07bb..0c574a5 100644
--- a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java
+++ b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java
@@ -125,6 +125,26 @@ public class MockSqlOperatorTable extends 
ChainedSqlOperatorTable {
     }
   }
 
+  /**
+   * "SPLIT" user-defined function. This function return array type
+   * in order to reproduce the throws of CALCITE-4062.
+   */
+  public static class SplitFunction extends SqlFunction {
+
+    public SplitFunction() {
+      super("SPLIT", new SqlIdentifier("SPLIT", SqlParserPos.ZERO), 
SqlKind.OTHER_FUNCTION, null,
+          null, OperandTypes.family(SqlTypeFamily.STRING, 
SqlTypeFamily.STRING), null,
+          SqlFunctionCategory.USER_DEFINED_FUNCTION);
+    }
+
+    @Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) 
{
+      final RelDataTypeFactory typeFactory =
+          opBinding.getTypeFactory();
+      return 
typeFactory.createArrayType(typeFactory.createSqlType(SqlTypeName.VARCHAR), -1);
+    }
+
+  }
+
   /** "MYAGG" user-defined aggregate function. This agg function accept two 
numeric arguments
    * in order to reproduce the throws of CALCITE-2744. */
   public static class MyAvgAggFunction extends SqlAggFunction {

Reply via email to