Repository: ignite
Updated Branches:
  refs/heads/ignite-2.5 9de5fce44 -> 88b574297


IGNITE-8052: SQL: clear error message when using a non-existing column name for 
CREATE TABLE primary key. This closes #3701.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/88b57429
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/88b57429
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/88b57429

Branch: refs/heads/ignite-2.5
Commit: 88b5742977564bd5a18b5ffff7bea25f6efa9ed2
Parents: 9de5fce
Author: shtykh_roman <[email protected]>
Authored: Thu Apr 26 12:55:29 2018 +0300
Committer: devozerov <[email protected]>
Committed: Thu Apr 26 12:56:05 2018 +0300

----------------------------------------------------------------------
 .../query/h2/sql/GridSqlQueryParser.java          |  4 +++-
 .../cache/index/H2DynamicTableSelfTest.java       | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/88b57429/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
index 2d2c25c..133333e 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
@@ -1041,7 +1041,9 @@ public class GridSqlQueryParser {
         for (IndexColumn pkIdxCol : pkIdxCols) {
             GridSqlColumn gridCol = cols.get(pkIdxCol.columnName);
 
-            assert gridCol != null;
+            if (gridCol == null)
+                throw new IgniteSQLException("PRIMARY KEY column is not 
defined: " + pkIdxCol.columnName,
+                    IgniteQueryErrorCode.PARSING);
 
             pkCols.add(gridCol.columnName());
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/88b57429/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
index 8224711..cd41419 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
@@ -72,6 +72,7 @@ import org.h2.value.DataType;
 /**
  * Tests for CREATE/DROP TABLE.
  */
+@SuppressWarnings("ThrowableNotThrown")
 public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
     /** Client node index. */
     private static final int CLIENT = 2;
@@ -720,6 +721,23 @@ public class H2DynamicTableSelfTest extends 
AbstractSchemaSelfTest {
     }
 
     /**
+     * Test that attempting to use a non-existing column name for the primary 
key when {@code CREATE TABLE}
+     * yields an error.
+     * @throws Exception if failed.
+     */
+    public void testCreateTableWithWrongColumnNameAsKey() throws Exception {
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                execute("CREATE TABLE \"Person\" (\"id\" int, \"city\" 
varchar" +
+                    ", \"name\" varchar, \"surname\" varchar, \"age\" int, 
PRIMARY KEY (\"id\", \"c_ity\")) WITH " +
+                    "\"template=cache\"");
+
+                return null;
+            }
+        }, IgniteSQLException.class, "PRIMARY KEY column is not defined: 
c_ity");
+    }
+
+    /**
      * Test that {@code DROP TABLE} actually removes specified cache and type 
descriptor on all nodes.
      * @throws Exception if failed.
      */

Reply via email to