Repository: ignite Updated Branches: refs/heads/master a0107c0b0 -> 34e22396c
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/34e22396 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/34e22396 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/34e22396 Branch: refs/heads/master Commit: 34e22396c985fe6f62b7f6e61b694ce08b409412 Parents: a0107c0 Author: shtykh_roman <[email protected]> Authored: Thu Apr 26 12:55:29 2018 +0300 Committer: devozerov <[email protected]> Committed: Thu Apr 26 12:55:29 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/34e22396/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/34e22396/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. */
