You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by da...@apache.org on 2019/06/28 01:13:25 UTC

[calcite] branch master updated: [CALCITE-3148] Validator throws IndexOutOfBoundsException for SqlInsert when source and sink have non-equal fields number

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

danny0405 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 6375e24  [CALCITE-3148] Validator throws IndexOutOfBoundsException for SqlInsert when source and sink have non-equal fields number
6375e24 is described below

commit 6375e24d4a8848e11e776ed6968f3a6f499424ae
Author: yuzhao.cyz <yu...@alibaba-inc.com>
AuthorDate: Thu Jun 27 10:59:32 2019 +0800

    [CALCITE-3148] Validator throws IndexOutOfBoundsException for SqlInsert when source and sink have non-equal fields number
---
 .../java/org/apache/calcite/sql/validate/SqlValidatorImpl.java   | 2 +-
 core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

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 e2a2e59..adfa42b 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
@@ -4070,7 +4070,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
             selectItem,
             select,
             targetRowType.isStruct()
-                && targetRowType.getFieldCount() >= i
+                && targetRowType.getFieldCount() > i
                 ? targetRowType.getFieldList().get(i).getType()
                 : unknownType,
             expandedSelectItems,
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 89e0d3b..e09881c 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -9132,6 +9132,15 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
         + "values (1, 'Karl')");
   }
 
+  @Test public void testInsertWithNonEqualSourceSinkFieldsNum() {
+    tester.checkQueryFails("insert into ^dept^ select sid, ename, deptno "
+        + "from "
+        + "(select sum(empno) as sid, ename, deptno, sal "
+        + "from emp group by ename, deptno, sal)",
+        "Number of INSERT target columns \\(2\\) "
+            + "does not equal number of source items \\(3\\)");
+  }
+
   @Test public void testInsertSubset() {
     final SqlTester pragmaticTester =
         tester.withConformance(SqlConformanceEnum.PRAGMATIC_2003);