Repository: calcite
Updated Branches:
  refs/heads/master 5c2164da9 -> 5547781ed


[CALCITE-2162] Exception when accessing sub-field of sub-field of composite 
Array element (Shuyi Chen)

Solve problem by changing stripDot method to be recursive.

Close apache/calcite#620

Change-Id: I950546b7d5c0bf24c8ef5eaa97a416377468c36c


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/5547781e
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/5547781e
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/5547781e

Branch: refs/heads/master
Commit: 5547781ede561133ce3440a0ee1c4de690f45863
Parents: 5c2164d
Author: Shuyi Chen <sh...@uber.com>
Authored: Thu Feb 1 14:50:57 2018 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Sat Feb 3 17:08:57 2018 -0800

----------------------------------------------------------------------
 .../apache/calcite/sql/validate/SqlValidatorImpl.java    |  2 +-
 .../java/org/apache/calcite/test/MockCatalogReader.java  | 10 +++++++++-
 .../org/apache/calcite/test/SqlToRelConverterTest.java   |  2 +-
 .../java/org/apache/calcite/test/SqlValidatorTest.java   | 11 ++++++++---
 .../org/apache/calcite/test/SqlToRelConverterTest.xml    |  4 ++--
 5 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/5547781e/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java 
b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index a8574f2..9c2170e 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -3292,7 +3292,7 @@ public class SqlValidatorImpl implements 
SqlValidatorWithHints {
 
   private SqlNode stripDot(SqlNode node) {
     if (node != null && node.getKind() == SqlKind.DOT) {
-      return ((SqlCall) node).operand(0);
+      return stripDot(((SqlCall) node).operand(0));
     }
     return node;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5547781e/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java 
b/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
index cd42747..23c6b94 100644
--- a/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
+++ b/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
@@ -1666,16 +1666,24 @@ public class MockCatalogReader extends 
CalciteCatalogReader {
                     .build())
             .kind(StructKind.PEEK_FIELDS_NO_EXPAND)
             .build();
+    final RelDataType abRecordType =
+        typeFactory.builder()
+            .add("A", varchar10Type)
+            .add("B", varchar10Type)
+            .build();
     final RelDataType skillRecordType =
         typeFactory.builder()
             .add("TYPE", varchar10Type)
             .add("DESC", varchar20Type)
+            .add("OTHERS", abRecordType)
             .build();
     final RelDataType empRecordType =
         typeFactory.builder()
             .add("EMPNO", intType)
             .add("ENAME", varchar10Type)
-            .add("SKILLS", typeFactory.createArrayType(skillRecordType, -1))
+            .add("DETAIL",
+                typeFactory.builder().add("SKILLS",
+                    typeFactory.createArrayType(skillRecordType, -1)).build())
             .build();
     final RelDataType empListType =
         typeFactory.createArrayType(empRecordType, -1);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5547781e/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index 9648ded..95a506b 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1103,7 +1103,7 @@ public class SqlToRelConverterTest extends 
SqlToRelTestBase {
   }
 
   @Test public void testArrayOfRecord() {
-    sql("select employees[1].skills[2+3].desc from dept_nested").ok();
+    sql("select employees[1].detail.skills[2+3].desc from dept_nested").ok();
   }
 
   @Test public void testUnnestArray() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/5547781e/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 3b0b831..82b7686 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -7433,8 +7433,9 @@ public class SqlValidatorTest extends 
SqlValidatorTestCase {
     final String type = "RecordType(INTEGER NOT NULL DEPTNO,"
         + " INTEGER NOT NULL EMPNO,"
         + " VARCHAR(10) NOT NULL ENAME,"
-        + " RecordType(VARCHAR(10) NOT NULL TYPE, VARCHAR(20) NOT NULL DESC)"
-        + " NOT NULL ARRAY NOT NULL SKILLS) NOT NULL";
+        + " RecordType(RecordType(VARCHAR(10) NOT NULL TYPE, VARCHAR(20) NOT 
NULL DESC,"
+        + " RecordType(VARCHAR(10) NOT NULL A, VARCHAR(10) NOT NULL B) NOT 
NULL OTHERS)"
+        + " NOT NULL ARRAY NOT NULL SKILLS) NOT NULL DETAIL) NOT NULL";
     sql(sql).type(type);
 
     // equivalent query using CROSS JOIN
@@ -7816,8 +7817,12 @@ public class SqlValidatorTest extends 
SqlValidatorTestCase {
         .fails("Unknown field 'NE'");
     sql("SELECT name, dept_nested.employees[1].ename as ename from 
dept_nested")
         .type("RecordType(VARCHAR(10) NOT NULL NAME, VARCHAR(10) ENAME) NOT 
NULL");
-    sql("SELECT dept_nested.employees[1].skills[1].desc as DESCRIPTION from 
dept_nested")
+    sql("SELECT dept_nested.employees[1].detail.skills[1].desc as 
DESCRIPTION\n"
+        + "from dept_nested")
         .type("RecordType(VARCHAR(20) DESCRIPTION) NOT NULL");
+    sql("SELECT dept_nested.employees[1].detail.skills[1].others.a as oa\n"
+        + "from dept_nested")
+        .type("RecordType(VARCHAR(10) OA) NOT NULL");
   }
 
   /** Test case for

http://git-wip-us.apache.org/repos/asf/calcite/blob/5547781e/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
----------------------------------------------------------------------
diff --git 
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml 
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index 48c6e00..f5d30af 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -361,11 +361,11 @@ window w as (partition by productId)]]>
     </TestCase>
     <TestCase name="testArrayOfRecord">
         <Resource name="sql">
-            <![CDATA[select employees[1].skills[2+3].desc from dept_nested]]>
+            <![CDATA[select employees[1].detail.skills[2+3].desc from 
dept_nested]]>
         </Resource>
         <Resource name="plan">
             <![CDATA[
-LogicalProject(EXPR$0=[DOT(ITEM(DOT(ITEM($2, 1), 'SKILLS'), +(2, 3)), 'DESC')])
+LogicalProject(EXPR$0=[DOT(ITEM(DOT(DOT(ITEM($2, 1), 'DETAIL'), 'SKILLS'), 
+(2, 3)), 'DESC')])
   LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
 ]]>
         </Resource>

Reply via email to