zstan commented on code in PR #13037:
URL: https://github.com/apache/ignite/pull/13037#discussion_r3115626192
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java:
##########
@@ -347,6 +348,208 @@ public void createTableIfNotExists() {
sql("create table if not exists my_table (id int, val varchar)");
}
+ /** Test that it's impossible to create tables with same name regardless
of key/value wrapping settings. */
+ @Test
+ public void createTableWithWrappedKeyVal() {
+ {
+ sql("create table t1 (id int primary key) WITH
\"wrap_value=false\"");
+ sql("create table t2 (id1 int, id2 int, primary key(id1, id2))
WITH \"wrap_value=false\"");
+
+ sql("DROP TABLE t1; DROP TABLE t2");
+ }
+ {
+ sql("create table my_table (id int, val varchar)");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_KEY, by default, this flag is set to false
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true\""),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true, wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+
+ {
+ sql("create table my_table (id int, val varchar) WITH
\"wrap_key=true\"");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true, wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+
+ {
+ sql("create table my_table (id int, val varchar) WITH
\"wrap_value=false\"");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true\""),
+ "Table already exists: MY_TABLE");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true, wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+
+ {
+ sql("create table my_table (id int, val varchar) WITH
\"wrap_key=true, wrap_value=false\"");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true\""),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+ }
+
+ /** Tests wrap=false is forbidden when key or value has more than one
column. */
+ @Test
+ public void testWrappingAlwaysOnWithComplexKV() {
+ assertThrowsSqlException(() -> sql("create table a (id int, x varchar,
c bigint, primary key(id, c)) with \"wrap_key=false\""),
+ "WRAP_KEY parameter cannot be \"false\" when composite primary key
exists.");
+
+ assertThrowsSqlException(() ->
+ sql("create table a (id int, x varchar, c bigint, primary
key(id)) with \"wrap_key=false, key_type=custom\""),
+ "WRAP_KEY parameter cannot be \"false\" when KEY_TYPE is
defined.");
+
+ assertThrowsSqlException(() -> sql("create table a (id int, x varchar,
c bigint, primary key(id)) with \"wrap_value=false\""),
+ "WRAP_VALUE parameter cannot be \"false\" with multiple columns.");
+
+ assertThrowsSqlException(() ->
+ sql("create table a (id int, x varchar, primary key(id)) with
\"wrap_value=false, value_type=custom\""),
+ "WRAP_VALUE parameter cannot be \"false\" when VALUE_TYPE is
defined.");
+ }
+
+ /** */
+ @SuppressWarnings("ThrowableNotThrown")
+ private static void assertThrowsSqlException(Callable<?> call, @Nullable
String msg) {
Review Comment:
the idea here is sequentially move to logic that sql related operations need
to throw IgniteSqlException (yes i know it internal but this is actual
reality..) from high level and (in the ideal case) this check method will
become commonly uset through sql tests. Move it into parent class.
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java:
##########
@@ -347,6 +348,208 @@ public void createTableIfNotExists() {
sql("create table if not exists my_table (id int, val varchar)");
}
+ /** Test that it's impossible to create tables with same name regardless
of key/value wrapping settings. */
+ @Test
+ public void createTableWithWrappedKeyVal() {
+ {
+ sql("create table t1 (id int primary key) WITH
\"wrap_value=false\"");
+ sql("create table t2 (id1 int, id2 int, primary key(id1, id2))
WITH \"wrap_value=false\"");
+
+ sql("DROP TABLE t1; DROP TABLE t2");
+ }
+ {
+ sql("create table my_table (id int, val varchar)");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_KEY, by default, this flag is set to false
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true\""),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true, wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+
+ {
+ sql("create table my_table (id int, val varchar) WITH
\"wrap_key=true\"");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true, wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+
+ {
+ sql("create table my_table (id int, val varchar) WITH
\"wrap_value=false\"");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true\""),
+ "Table already exists: MY_TABLE");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true, wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+
+ {
+ sql("create table my_table (id int, val varchar) WITH
\"wrap_key=true, wrap_value=false\"");
+
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar)"),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_key=true\""),
+ "Table already exists: MY_TABLE");
+
+ // WRAP_VALUE, by default, this flag is set to true
+ assertThrowsSqlException(() -> sql("create table my_table (id int,
val varchar) WITH \"wrap_value=false\""),
+ "Table already exists: MY_TABLE");
+
+ sql("DROP TABLE my_table");
+ }
+ }
+
+ /** Tests wrap=false is forbidden when key or value has more than one
column. */
+ @Test
+ public void testWrappingAlwaysOnWithComplexKV() {
+ assertThrowsSqlException(() -> sql("create table a (id int, x varchar,
c bigint, primary key(id, c)) with \"wrap_key=false\""),
+ "WRAP_KEY parameter cannot be \"false\" when composite primary key
exists.");
+
+ assertThrowsSqlException(() ->
+ sql("create table a (id int, x varchar, c bigint, primary
key(id)) with \"wrap_key=false, key_type=custom\""),
+ "WRAP_KEY parameter cannot be \"false\" when KEY_TYPE is
defined.");
+
+ assertThrowsSqlException(() -> sql("create table a (id int, x varchar,
c bigint, primary key(id)) with \"wrap_value=false\""),
+ "WRAP_VALUE parameter cannot be \"false\" with multiple columns.");
+
+ assertThrowsSqlException(() ->
+ sql("create table a (id int, x varchar, primary key(id)) with
\"wrap_value=false, value_type=custom\""),
+ "WRAP_VALUE parameter cannot be \"false\" when VALUE_TYPE is
defined.");
+ }
+
+ /** */
+ @SuppressWarnings("ThrowableNotThrown")
+ private static void assertThrowsSqlException(Callable<?> call, @Nullable
String msg) {
+ GridTestUtils.assertThrows(log, call, IgniteSQLException.class, msg);
+ }
+
+ /**
+ * Test that {@code ADD COLUMN} fails.
+ */
+ @Test
+ public void testAlterTableFailOnSingleCacheValue() {
+ CacheConfiguration c =
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]