You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2023/05/15 09:07:20 UTC

[incubator-paimon] branch master updated: [test] Add test for ADD/DROP/MODIFY columns for Flink 1.17 (#1153)

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

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new a0ebdef61 [test] Add test for ADD/DROP/MODIFY columns for Flink 1.17 (#1153)
a0ebdef61 is described below

commit a0ebdef61267085e3f4ca5855201705bf6ea79d4
Author: Dian Qi <qi...@163.com>
AuthorDate: Mon May 15 17:07:13 2023 +0800

    [test] Add test for ADD/DROP/MODIFY columns for Flink 1.17 (#1153)
---
 .../apache/paimon/flink/SchemaChangeITCase.java    | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java
index 61d9029b5..8003fcca6 100644
--- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java
+++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java
@@ -500,4 +500,65 @@ public class SchemaChangeITCase extends CatalogITCaseBase {
                 .isInstanceOf(UnsupportedOperationException.class)
                 .hasMessage("Change 'sequence.field' is not supported yet.");
     }
+
+    @Test
+    public void testAlterTableSchema() {
+        sql("CREATE TABLE T (a STRING, b STRING COMMENT 'from column b')");
+        List<String> result =
+                sql("DESC T").stream().map(Objects::toString).collect(Collectors.toList());
+        assertThat(result)
+                .containsExactlyInAnyOrder(
+                        "+I[a, STRING, true, null, null, null, null]",
+                        "+I[b, STRING, true, null, null, null, from column b]");
+
+        // add columns at different positions
+        sql("ALTER TABLE T ADD (c INT AFTER b)");
+        result = sql("DESC T").stream().map(Objects::toString).collect(Collectors.toList());
+        assertThat(result)
+                .containsExactlyInAnyOrder(
+                        "+I[a, STRING, true, null, null, null, null]",
+                        "+I[b, STRING, true, null, null, null, from column b]",
+                        "+I[c, INT, true, null, null, null, null]");
+
+        sql("ALTER TABLE T ADD (d INT FIRST)");
+        result = sql("DESC T").stream().map(Objects::toString).collect(Collectors.toList());
+        assertThat(result)
+                .containsExactlyInAnyOrder(
+                        "+I[d, INT, true, null, null, null, null]",
+                        "+I[a, STRING, true, null, null, null, null]",
+                        "+I[b, STRING, true, null, null, null, from column b]",
+                        "+I[c, INT, true, null, null, null, null]");
+
+        // drop previously added column
+        sql("ALTER TABLE T DROP d");
+        result = sql("DESC T").stream().map(Objects::toString).collect(Collectors.toList());
+        assertThat(result)
+                .containsExactlyInAnyOrder(
+                        "+I[a, STRING, true, null, null, null, null]",
+                        "+I[b, STRING, true, null, null, null, from column b]",
+                        "+I[c, INT, true, null, null, null, null]");
+
+        // change column type
+        sql("ALTER TABLE T MODIFY (c BIGINT)");
+        result = sql("DESC T").stream().map(Objects::toString).collect(Collectors.toList());
+        assertThat(result)
+                .containsExactlyInAnyOrder(
+                        "+I[a, STRING, true, null, null, null, null]",
+                        "+I[b, STRING, true, null, null, null, from column b]",
+                        "+I[c, BIGINT, true, null, null, null, null]");
+
+        // invalid type change: BIGINT to INT
+        assertThatThrownBy(() -> sql("ALTER TABLE T MODIFY (c INT)"))
+                .getRootCause()
+                .isInstanceOf(IllegalStateException.class)
+                .hasMessage(
+                        "Column type c[BIGINT] cannot be converted to INT without loosing information.");
+
+        // invalid type change: BIGINT to STRING
+        assertThatThrownBy(() -> sql("ALTER TABLE T MODIFY (c STRING)"))
+                .getRootCause()
+                .isInstanceOf(IllegalStateException.class)
+                .hasMessage(
+                        "Column type c[BIGINT] cannot be converted to STRING without loosing information.");
+    }
 }