You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2024/05/28 15:14:31 UTC

(ignite-3) branch ignite-21969 created (now 78f069a0f7)

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

amashenkov pushed a change to branch ignite-21969
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


      at 78f069a0f7 minor

This branch includes the following new commits:

     new 78f069a0f7 minor

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(ignite-3) 01/01: minor

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21969
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 78f069a0f7c9743d28cf8f65f1629f53a2025aed
Author: amashenkov <an...@gmail.com>
AuthorDate: Tue May 28 18:14:19 2024 +0300

    minor
---
 .../sql/engine/ItAlterTableAlterColumnTest.java    |   2 +
 .../internal/sql/engine/ItAlterTableDdlTest.java   | 200 +++++++++++++++++++++
 .../internal/sql/engine/ItCreateTableDdlTest.java  | 154 +---------------
 3 files changed, 204 insertions(+), 152 deletions(-)

diff --git a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableAlterColumnTest.java b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableAlterColumnTest.java
index 6f5c68f58a..f9ca05c409 100644
--- a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableAlterColumnTest.java
+++ b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableAlterColumnTest.java
@@ -46,6 +46,8 @@ import org.junit.jupiter.params.provider.MethodSource;
 
 /**
  * Integration test for ALTER TABLE ALTER COLUMN command.
+ * <p>
+ * SQL F381 feature. Extended schema manipulation.
  */
 public class ItAlterTableAlterColumnTest extends BaseSqlIntegrationTest {
     @AfterEach
diff --git a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java
new file mode 100644
index 0000000000..bdb67387cf
--- /dev/null
+++ b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine;
+
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
+import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_PARSE_ERR;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.Month;
+import java.util.List;
+import java.util.Set;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.lang.IgniteStringBuilder;
+import org.apache.ignite.internal.schema.SchemaTestUtils;
+import org.apache.ignite.internal.sql.BaseSqlIntegrationTest;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.sql.engine.util.TypeUtils;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypeSpec;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for ALTER TABLE DDL statements.
+ * <p>
+ * SQL F031-04 feature. ALTER TABLE statement: ADD COLUMN clause
+ * SQL F033 feature. ALTER TABLE statement: DROP COLUMN clause
+ */
+public class ItAlterTableDdlTest extends BaseSqlIntegrationTest {
+    @AfterEach
+    public void dropTables() {
+        dropAllTables();
+        dropAllZonesExceptDefaultOne();
+    }
+
+    /** Test correct mapping schema after alter columns. */
+    @Test
+    public void testDropAndAddColumns() {
+        sql("CREATE TABLE my (c1 INT PRIMARY KEY, c2 INT, c3 VARCHAR)");
+
+        sql("INSERT INTO my VALUES (1, 2, '3')");
+
+        List<List<Object>> res = sql("SELECT c1, c3 FROM my");
+
+        assertFalse(res.isEmpty());
+
+        sql("ALTER TABLE my DROP COLUMN c2");
+
+        res = sql("SELECT c1, c3 FROM my");
+
+        assertFalse(res.isEmpty());
+
+        sql("ALTER TABLE my ADD COLUMN (c2 INT, c4 VARCHAR)");
+
+        sql("INSERT INTO my VALUES (2, '2', 2, '3')");
+
+        res = sql("SELECT c2, c4 FROM my WHERE c1=2");
+
+        assertEquals(2, res.get(0).get(0));
+
+        sql("ALTER TABLE my DROP COLUMN c4");
+        sql("ALTER TABLE my ADD COLUMN (c4 INT)");
+        sql("INSERT INTO my VALUES (3, '2', 3, 3)");
+
+        res = sql("SELECT c4 FROM my WHERE c1=3");
+
+        assertEquals(3, res.get(0).get(0));
+
+        // Checking the correctness of reading a row created on a different version of the schema.
+        sql("ALTER TABLE my ADD COLUMN (c5 VARCHAR, c6 BOOLEAN)");
+        sql("ALTER TABLE my DROP COLUMN c4");
+        assertQuery("SELECT * FROM my WHERE c1=3")
+                .returns(3, "2", 3, null, null)
+                .check();
+    }
+
+    /** Test that adding nullable column via ALTER TABLE ADD name type NULL works. */
+    @Test
+    public void testNullableColumn() {
+        sql("CREATE TABLE my (c1 INT PRIMARY KEY, c2 INT)");
+        sql("INSERT INTO my VALUES (1, 1)");
+        sql("ALTER TABLE my ADD COLUMN c3 INT NULL");
+        sql("INSERT INTO my VALUES (2, 2, NULL)");
+
+        assertQuery("SELECT * FROM my ORDER by c1 ASC")
+                .returns(1, 1, null)
+                .returns(2, 2, null)
+                .check();
+    }
+
+    /**
+     * Adds columns of all supported types and checks that the row
+     * created on the old schema version is read correctly.
+     */
+    @Test
+    public void testDropAndAddColumnsAllTypes() {
+        List<NativeType> allTypes = SchemaTestUtils.ALL_TYPES;
+
+        Set<NativeTypeSpec> unsupportedTypes = Set.of(
+                // TODO https://issues.apache.org/jira/browse/IGNITE-18431
+                NativeTypeSpec.BITMASK
+        );
+
+        // List of columns for 'ADD COLUMN' statement.
+        IgniteStringBuilder addColumnsList = new IgniteStringBuilder();
+        // List of columns for 'DROP COLUMN' statement.
+        IgniteStringBuilder dropColumnsList = new IgniteStringBuilder();
+
+        for (int i = 0; i < allTypes.size(); i++) {
+            NativeType type = allTypes.get(i);
+
+            if (unsupportedTypes.contains(type.spec())) {
+                continue;
+            }
+
+            RelDataType relDataType = TypeUtils.native2relationalType(Commons.typeFactory(), type);
+
+            if (addColumnsList.length() > 0) {
+                addColumnsList.app(',');
+                dropColumnsList.app(',');
+            }
+
+            addColumnsList.app("c").app(i).app(' ').app(relDataType.getSqlTypeName().getSpaceName());
+            dropColumnsList.app("c").app(i);
+        }
+
+        sql("CREATE TABLE test (id INT PRIMARY KEY, val INT)");
+        sql("INSERT INTO test VALUES (0, 1)");
+        sql(format("ALTER TABLE test ADD COLUMN ({})", addColumnsList.toString()));
+
+        List<List<Object>> res = sql("SELECT * FROM test");
+        assertThat(res.size(), is(1));
+        assertThat(res.get(0).size(), is(allTypes.size() - unsupportedTypes.size() + /* initial columns */ 2));
+
+        sql(format("ALTER TABLE test DROP COLUMN ({})", dropColumnsList.toString()));
+        assertQuery("SELECT * FROM test")
+                .returns(0, 1)
+                .check();
+    }
+
+
+    @Test
+    public void addColumnWithConstantDefault() {
+        sql("CREATE TABLE test(id BIGINT DEFAULT 1 PRIMARY KEY)");
+
+        sql("ALTER TABLE test ADD COLUMN valint INTEGER DEFAULT 1");
+        sql("ALTER TABLE test ADD COLUMN valdate DATE DEFAULT DATE '2001-12-21'");
+        sql("ALTER TABLE test ADD COLUMN valtime TIME(3) DEFAULT TIME '11:22:33.444555'");
+        sql("ALTER TABLE test ADD COLUMN valts TIMESTAMP(3) DEFAULT TIMESTAMP '2001-12-21 11:22:33.444555'");
+        sql("ALTER TABLE test ADD COLUMN valstr VARCHAR DEFAULT 'string'");
+        sql("ALTER TABLE test ADD COLUMN valbin VARBINARY DEFAULT x'ff'");
+
+        sql("INSERT INTO test (id) VALUES (0)");
+
+        assertQuery("SELECT * FROM test")
+                .returns(0L,
+                        1,
+                        LocalDate.of(2001, Month.DECEMBER, 21),
+                        LocalTime.of(11, 22, 33, 444000000),
+                        LocalDateTime.of(2001, Month.DECEMBER, 21, 11, 22, 33, 444000000),
+                        "string",
+                        new byte[]{(byte) 0xff}
+                )
+                .check();
+    }
+
+    @Test
+    @SuppressWarnings("ThrowableNotThrown")
+    public void doNotAllowFunctionsInNonPkColumns() {
+        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY, val VARCHAR)");
+
+        assertThrowsSqlException(
+                STMT_PARSE_ERR,
+                "Failed to parse query: Encountered \"rand_uuid\"",
+                () -> sql("ALTER TABLE t ADD COLUMN val2 VARCHAR DEFAULT rand_uuid")
+        );
+    }
+}
diff --git a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java
index 9ba18a8873..6769a72d6b 100644
--- a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java
+++ b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java
@@ -26,32 +26,18 @@ import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_PARSE_ERR;
 import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
 
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.Month;
 import java.util.List;
 import java.util.Objects;
-import java.util.Set;
 import java.util.stream.Stream;
-import org.apache.calcite.rel.type.RelDataType;
 import org.apache.ignite.internal.app.IgniteImpl;
 import org.apache.ignite.internal.catalog.Catalog;
 import org.apache.ignite.internal.catalog.CatalogManager;
 import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
 import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor;
-import org.apache.ignite.internal.lang.IgniteStringBuilder;
 import org.apache.ignite.internal.schema.Column;
-import org.apache.ignite.internal.schema.SchemaTestUtils;
 import org.apache.ignite.internal.sql.BaseSqlIntegrationTest;
-import org.apache.ignite.internal.sql.engine.util.Commons;
-import org.apache.ignite.internal.sql.engine.util.TypeUtils;
-import org.apache.ignite.internal.type.NativeType;
-import org.apache.ignite.internal.type.NativeTypeSpec;
 import org.apache.ignite.sql.SqlException;
 import org.apache.ignite.tx.Transaction;
 import org.apache.ignite.tx.TransactionOptions;
@@ -63,6 +49,8 @@ import org.junit.jupiter.params.provider.MethodSource;
 
 /**
  * Integration tests for DDL statements that affect tables.
+ * <p>
+ * SQL F031-01 feature. CREATE TABLE statement to create persistent base tables
  */
 public class ItCreateTableDdlTest extends BaseSqlIntegrationTest {
     @AfterEach
@@ -203,111 +191,6 @@ public class ItCreateTableDdlTest extends BaseSqlIntegrationTest {
         assertEquals("ID0", colocationColumns.get(1).name());
     }
 
-    /** Test correct mapping schema after alter columns. */
-    @Test
-    public void testDropAndAddColumns() {
-        sql("CREATE TABLE my (c1 INT PRIMARY KEY, c2 INT, c3 VARCHAR)");
-
-        sql("INSERT INTO my VALUES (1, 2, '3')");
-
-        List<List<Object>> res = sql("SELECT c1, c3 FROM my");
-
-        assertFalse(res.isEmpty());
-
-        sql("ALTER TABLE my DROP COLUMN c2");
-
-        res = sql("SELECT c1, c3 FROM my");
-
-        assertFalse(res.isEmpty());
-
-        sql("ALTER TABLE my ADD COLUMN (c2 INT, c4 VARCHAR)");
-
-        sql("INSERT INTO my VALUES (2, '2', 2, '3')");
-
-        res = sql("SELECT c2, c4 FROM my WHERE c1=2");
-
-        assertEquals(2, res.get(0).get(0));
-
-        sql("ALTER TABLE my DROP COLUMN c4");
-        sql("ALTER TABLE my ADD COLUMN (c4 INT)");
-        sql("INSERT INTO my VALUES (3, '2', 3, 3)");
-
-        res = sql("SELECT c4 FROM my WHERE c1=3");
-
-        assertEquals(3, res.get(0).get(0));
-
-        // Checking the correctness of reading a row created on a different version of the schema.
-        sql("ALTER TABLE my ADD COLUMN (c5 VARCHAR, c6 BOOLEAN)");
-        sql("ALTER TABLE my DROP COLUMN c4");
-        assertQuery("SELECT * FROM my WHERE c1=3")
-                .returns(3, "2", 3, null, null)
-                .check();
-    }
-
-    /** Test that adding nullable column via ALTER TABLE ADD name type NULL works. */
-    @Test
-    public void testNullableColumn() {
-        sql("CREATE TABLE my (c1 INT PRIMARY KEY, c2 INT)");
-        sql("INSERT INTO my VALUES (1, 1)");
-        sql("ALTER TABLE my ADD COLUMN c3 INT NULL");
-        sql("INSERT INTO my VALUES (2, 2, NULL)");
-
-        assertQuery("SELECT * FROM my ORDER by c1 ASC")
-                .returns(1, 1, null)
-                .returns(2, 2, null)
-                .check();
-    }
-
-    /**
-     * Adds columns of all supported types and checks that the row
-     * created on the old schema version is read correctly.
-     */
-    @Test
-    public void testDropAndAddColumnsAllTypes() {
-        List<NativeType> allTypes = SchemaTestUtils.ALL_TYPES;
-
-        Set<NativeTypeSpec> unsupportedTypes = Set.of(
-                // TODO https://issues.apache.org/jira/browse/IGNITE-18431
-                NativeTypeSpec.BITMASK
-        );
-
-        // List of columns for 'ADD COLUMN' statement.
-        IgniteStringBuilder addColumnsList = new IgniteStringBuilder();
-        // List of columns for 'DROP COLUMN' statement.
-        IgniteStringBuilder dropColumnsList = new IgniteStringBuilder();
-
-        for (int i = 0; i < allTypes.size(); i++) {
-            NativeType type = allTypes.get(i);
-
-            if (unsupportedTypes.contains(type.spec())) {
-                continue;
-            }
-
-            RelDataType relDataType = TypeUtils.native2relationalType(Commons.typeFactory(), type);
-
-            if (addColumnsList.length() > 0) {
-                addColumnsList.app(',');
-                dropColumnsList.app(',');
-            }
-
-            addColumnsList.app("c").app(i).app(' ').app(relDataType.getSqlTypeName().getSpaceName());
-            dropColumnsList.app("c").app(i);
-        }
-
-        sql("CREATE TABLE test (id INT PRIMARY KEY, val INT)");
-        sql("INSERT INTO test VALUES (0, 1)");
-        sql(format("ALTER TABLE test ADD COLUMN ({})", addColumnsList.toString()));
-
-        List<List<Object>> res = sql("SELECT * FROM test");
-        assertThat(res.size(), is(1));
-        assertThat(res.get(0).size(), is(allTypes.size() - unsupportedTypes.size() + /* initial columns */ 2));
-
-        sql(format("ALTER TABLE test DROP COLUMN ({})", dropColumnsList.toString()));
-        assertQuery("SELECT * FROM test")
-                .returns(0, 1)
-                .check();
-    }
-
     /**
      * Check explicit colocation columns configuration.
      */
@@ -350,31 +233,6 @@ public class ItCreateTableDdlTest extends BaseSqlIntegrationTest {
         assertEquals(6, columns.size());
     }
 
-    @Test
-    public void addColumnWithConstantDefault() {
-        sql("CREATE TABLE test(id BIGINT DEFAULT 1 PRIMARY KEY)");
-
-        sql("ALTER TABLE test ADD COLUMN valint INTEGER DEFAULT 1");
-        sql("ALTER TABLE test ADD COLUMN valdate DATE DEFAULT DATE '2001-12-21'");
-        sql("ALTER TABLE test ADD COLUMN valtime TIME(3) DEFAULT TIME '11:22:33.444555'");
-        sql("ALTER TABLE test ADD COLUMN valts TIMESTAMP(3) DEFAULT TIMESTAMP '2001-12-21 11:22:33.444555'");
-        sql("ALTER TABLE test ADD COLUMN valstr VARCHAR DEFAULT 'string'");
-        sql("ALTER TABLE test ADD COLUMN valbin VARBINARY DEFAULT x'ff'");
-
-        sql("INSERT INTO test (id) VALUES (0)");
-
-        assertQuery("SELECT * FROM test")
-                .returns(0L,
-                        1,
-                        LocalDate.of(2001, Month.DECEMBER, 21),
-                        LocalTime.of(11, 22, 33, 444000000),
-                        LocalDateTime.of(2001, Month.DECEMBER, 21, 11, 22, 33, 444000000),
-                        "string",
-                        new byte[]{(byte) 0xff}
-                        )
-                .check();
-    }
-
     @Test
     @SuppressWarnings("ThrowableNotThrown")
     public void doNotAllowFunctionsInNonPkColumns() {
@@ -383,14 +241,6 @@ public class ItCreateTableDdlTest extends BaseSqlIntegrationTest {
                 "Functional defaults are not supported for non-primary key columns",
                 () -> sql("CREATE TABLE t (id VARCHAR PRIMARY KEY, val UUID DEFAULT rand_uuid)")
         );
-
-        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY, val VARCHAR)");
-
-        assertThrowsSqlException(
-                STMT_PARSE_ERR,
-                "Failed to parse query: Encountered \"rand_uuid\"",
-                () -> sql("ALTER TABLE t ADD COLUMN val2 VARCHAR DEFAULT rand_uuid")
-        );
     }
 
     @ParameterizedTest