zstan commented on code in PR #13037:
URL: https://github.com/apache/ignite/pull/13037#discussion_r3118479819


##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ddl/DdlCommandHandler.java:
##########
@@ -386,6 +423,22 @@ else if (!F.isEmpty(cmd.primaryKeyColumns()) && 
cmd.primaryKeyColumns().size() =
             res = new QueryEntityEx(res).implicitPk(true);
         }
 
+        if (!cmd.wrapValue()) {

Review Comment:
   done



##########
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:
   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]

Reply via email to