From 9317d61b8ad33cf8a08300e3c6043a0c02da8e4d Mon Sep 17 00:00:00 2001 From: yantian Date: Thu, 9 Jan 2025 11:36:25 +0800 Subject: [PATCH] add alter table IT case for RESTCatalog --- .../paimon/rest/MockRESTCatalogServer.java | 1 - .../paimon/flink/RESTCatalogITCase.java | 42 +++++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java b/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java index 43b0dc706df6..3d5013282fe1 100644 --- a/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java +++ b/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogServer.java @@ -91,7 +91,6 @@ public static Dispatcher initDispatcher(Catalog catalog, String authToken) { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { - System.out.println(request.getPath() + " method " + request.getMethod()); String token = request.getHeaders().get("Authorization"); RESTResponse response; try { diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java index 7f6cde5f3d8f..8491cdfa7d0e 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java @@ -21,6 +21,7 @@ import org.apache.paimon.rest.MockRESTCatalogServer; import org.apache.paimon.rest.RESTCatalogOptions; +import org.apache.flink.types.Row; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -28,6 +29,7 @@ import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -35,6 +37,9 @@ /** ITCase for REST catalog. */ public class RESTCatalogITCase extends CatalogITCaseBase { + private static final String databaseName = "mydb"; + private static final String tableName = "t1"; + MockRESTCatalogServer mockRESTCatalogServer; private String serverUrl; protected String warehouse; @@ -48,23 +53,44 @@ public void before() throws IOException { mockRESTCatalogServer.start(); serverUrl = mockRESTCatalogServer.getUrl(); super.before(); + sql(String.format("CREATE DATABASE %s", databaseName)); + sql(String.format("CREATE TABLE %s.%s (a STRING, b DOUBLE)", databaseName, tableName)); } @AfterEach() public void after() throws IOException { + sql(String.format("DROP TABLE %s.%s", databaseName, tableName)); + sql(String.format("DROP DATABASE %s", databaseName)); mockRESTCatalogServer.shutdown(); } @Test public void testCreateTable() { - sql("CREATE DATABASE mydb"); - sql("CREATE TABLE mydb.T1 (a INT, b INT)"); - String result = sql("DESCRIBE mydb.T1").toString(); - assertThat(result) - .isEqualTo( - "[+I[a, INT, true, null, null, null], +I[b, INT, true, null, null, null]]"); - sql("DROP TABLE mydb.T1"); - sql("DROP DATABASE mydb"); + List result = sql(String.format("SHOW CREATE TABLE %s.%s", databaseName, tableName)); + assertThat(result.toString()) + .contains( + String.format( + "CREATE TABLE `PAIMON`.`%s`.`%s` (\n" + + " `a` VARCHAR(2147483647),\n" + + " `b` DOUBLE", + databaseName, tableName)); + } + + @Test + public void testAlterTable() { + sql(String.format("ALTER TABLE %s.%s ADD e INT AFTER b", databaseName, tableName)); + sql(String.format("ALTER TABLE %s.%s DROP b", databaseName, tableName)); + ; + sql(String.format("ALTER TABLE %s.%s RENAME a TO a1", databaseName, tableName)); + ; + List result = sql(String.format("SHOW CREATE TABLE %s.%s", databaseName, tableName)); + assertThat(result.toString()) + .contains( + String.format( + "CREATE TABLE `PAIMON`.`%s`.`%s` (\n" + + " `a1` VARCHAR(2147483647),\n" + + " `e` INT", + databaseName, tableName)); } @Override