From d4f32ff3c1587a09b0d1c10a5f93f40c50d267cc Mon Sep 17 00:00:00 2001 From: stephen <91597003+stephen-shelby@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:29:50 +0800 Subject: [PATCH 1/3] [Enhancement] desc iceberg table with transform type (#49094) Signed-off-by: stephen (cherry picked from commit 4855c19b37faeb2769dc40604103fb6e1ab2d3e3) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java # fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java # fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java --- .../com/starrocks/catalog/IcebergTable.java | 10 ++ .../iceberg/IcebergApiConverter.java | 97 +++++++++++++++++++ .../sql/analyzer/AstToStringBuilder.java | 13 ++- .../connector/hive/HiveMetadataTest.java | 2 +- .../com/starrocks/qe/ShowExecutorTest.java | 66 +++++++++++++ .../sql/test_iceberg/R/test_iceberg_show_stmt | 21 ++++ .../sql/test_iceberg/T/test_iceberg_show_stmt | 7 ++ 7 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 test/sql/test_iceberg/R/test_iceberg_show_stmt create mode 100644 test/sql/test_iceberg/T/test_iceberg_show_stmt diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java b/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java index 71f8fbf635c67..65751e491259c 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java @@ -45,6 +45,7 @@ import com.starrocks.thrift.TTableType; import org.apache.iceberg.BaseTable; import org.apache.iceberg.PartitionField; +import org.apache.iceberg.PartitionSpec; import org.apache.iceberg.Schema; import org.apache.iceberg.Snapshot; import org.apache.iceberg.SortField; @@ -283,6 +284,11 @@ public List getPartitionColumnNames() { .collect(Collectors.toList()); } + public List getPartitionColumnNamesWithTransform() { + PartitionSpec partitionSpec = getNativeTable().spec(); + return IcebergApiConverter.toPartitionFields(partitionSpec); + } + @Override public String getTableIdentifier() { String uuid = ((BaseTable) getNativeTable()).operations().current().uuid(); @@ -318,6 +324,7 @@ public org.apache.iceberg.Table getNativeTable() { } return nativeTable; } +<<<<<<< HEAD public long getRefreshSnapshotTime() { return refreshSnapshotTime; @@ -327,6 +334,9 @@ public void setRefreshSnapshotTime(long refreshSnapshotTime) { this.refreshSnapshotTime = refreshSnapshotTime; } +======= + +>>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) public void setIdentifierFieldIds(Set identifierFieldIds) { this.identifierFieldIds = identifierFieldIds; } diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java b/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java index b1d1c361af449..56167c46abab1 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java @@ -33,6 +33,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.iceberg.FileFormat; import org.apache.iceberg.Metrics; +import org.apache.iceberg.PartitionField; import org.apache.iceberg.PartitionSpec; import org.apache.iceberg.Schema; import org.apache.iceberg.Table; @@ -50,16 +51,30 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +<<<<<<< HEAD +======= +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +>>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.starrocks.analysis.OutFileClause.PARQUET_COMPRESSION_TYPE_MAP; import static com.starrocks.connector.ColumnTypeConverter.fromIcebergType; import static com.starrocks.connector.ConnectorTableId.CONNECTOR_ID_GENERATOR; import static com.starrocks.connector.iceberg.IcebergConnector.ICEBERG_CATALOG_TYPE; import static com.starrocks.server.CatalogMgr.ResourceMappingCatalog.toResourceName; +<<<<<<< HEAD +======= +import static java.lang.String.format; +import static org.apache.iceberg.view.ViewProperties.COMMENT; +>>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) public class IcebergApiConverter { private static final Logger LOG = LogManager.getLogger(IcebergApiConverter.class); public static final String PARTITION_NULL_VALUE = "null"; + private static final Pattern ICEBERG_BUCKET_PATTERN = Pattern.compile("bucket\\[(\\d+)]"); + private static final Pattern ICEBERG_TRUNCATE_PATTERN = Pattern.compile("truncate\\[(\\d+)]"); private static final int FAKE_FIELD_ID = -1; public static IcebergTable toIcebergTable(Table nativeTbl, String catalogName, String remoteDbName, @@ -293,4 +308,86 @@ public static Map rebuildCreateTableProperties(Map filterManifests(List manifests, + org.apache.iceberg.Table table, Expression filter) { + Map evalCache = specCache(table, filter); + + return manifests.stream() + .filter(manifest -> manifest.hasAddedFiles() || manifest.hasExistingFiles()) + .filter(manifest -> evalCache.get(manifest.partitionSpecId()).eval(manifest)) + .collect(Collectors.toList()); + } + + private static Map specCache(org.apache.iceberg.Table table, Expression filter) { + Map cache = new ConcurrentHashMap<>(); + + for (Map.Entry entry : table.specs().entrySet()) { + Integer spedId = entry.getKey(); + PartitionSpec spec = entry.getValue(); + + Expression projection = Projections.inclusive(spec, false).project(filter); + ManifestEvaluator evaluator = ManifestEvaluator.forPartitionFilter(projection, spec, false); + + cache.put(spedId, evaluator); + } + return cache; + } + + public static boolean mayHaveEqualityDeletes(Snapshot snapshot) { + String count = snapshot.summary().get(SnapshotSummary.TOTAL_EQ_DELETES_PROP); + return count == null || !count.equals("0"); + } + + public static IcebergView toView(String catalogName, String dbName, View icebergView) { + SQLViewRepresentation sqlView = icebergView.sqlFor("starrocks"); + String comment = icebergView.properties().get(COMMENT); + List columns = toFullSchemas(icebergView.schema()); + ViewVersion currentVersion = icebergView.currentVersion(); + String defaultCatalogName = currentVersion.defaultCatalog(); + String defaultDbName = currentVersion.defaultNamespace().level(0); + String viewName = icebergView.name(); + String location = icebergView.location(); + IcebergView view = new IcebergView(CONNECTOR_ID_GENERATOR.getNextId().asInt(), catalogName, dbName, viewName, + columns, sqlView.sql(), defaultCatalogName, defaultDbName, location); + view.setComment(comment); + return view; + } + + public static List toPartitionFields(PartitionSpec spec) { + return spec.fields().stream() + .map(field -> toPartitionField(spec, field)) + .collect(toImmutableList()); + } + + private static String toPartitionField(PartitionSpec spec, PartitionField field) { + String name = spec.schema().findColumnName(field.sourceId()); + String transform = field.transform().toString(); + + switch (transform) { + case "identity": + return name; + case "year": + case "month": + case "day": + case "hour": + case "void": + return format("%s(%s)", transform, name); + } + + Matcher matcher = ICEBERG_BUCKET_PATTERN.matcher(transform); + if (matcher.matches()) { + return format("bucket(%s, %s)", name, matcher.group(1)); + } + + matcher = ICEBERG_TRUNCATE_PATTERN.matcher(transform); + if (matcher.matches()) { + return format("truncate(%s, %s)", name, matcher.group(1)); + } + + throw new StarRocksConnectorException("Unsupported partition transform: " + field); + } +>>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) } \ No newline at end of file diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java index d480fb38124c8..bc5857d7ed9c3 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java @@ -1351,10 +1351,17 @@ public static String getExternalCatalogTableDdlStmt(Table table) { .append("\n)"); // Partition column names + List partitionNames; if (table.getType() != JDBC && !table.isUnPartitioned()) { - createTableSql.append("\nPARTITION BY ( ") - .append(String.join(", ", table.getPartitionColumnNames())) - .append(" )"); + createTableSql.append("\nPARTITION BY ("); + + if (!table.isIcebergTable()) { + partitionNames = table.getPartitionColumnNames(); + } else { + partitionNames = ((IcebergTable) table).getPartitionColumnNamesWithTransform(); + } + + createTableSql.append(String.join(", ", partitionNames)).append(")"); } // Location diff --git a/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveMetadataTest.java b/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveMetadataTest.java index 8ecd8f69ea426..e15dc72429140 100644 --- a/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveMetadataTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveMetadataTest.java @@ -263,7 +263,7 @@ public void testShowCreateHiveTbl() { " `col2` int(11) DEFAULT NULL,\n" + " `col1` int(11) DEFAULT NULL\n" + ")\n" + - "PARTITION BY ( col1 )\n" + + "PARTITION BY (col1)\n" + "PROPERTIES (\"location\" = \"hdfs://127.0.0.1:10000/hive\");", AstToStringBuilder.getExternalCatalogTableDdlStmt(hiveTable)); } diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java index 0588d1dd79c11..b06dff908c2e6 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java @@ -1088,6 +1088,7 @@ public Table getTable(String catalogName, String dbName, String tblName) { ShowResultSet resultSet = executor.execute(); Assert.assertEquals("test_table", resultSet.getResultRows().get(0).get(0)); Assert.assertEquals("CREATE TABLE `test_table` (\n" + +<<<<<<< HEAD " `id` int(11) DEFAULT NULL COMMENT \"id\",\n" + " `name` varchar DEFAULT NULL,\n" + " `year` int(11) DEFAULT NULL,\n" + @@ -1095,6 +1096,71 @@ public Table getTable(String catalogName, String dbName, String tblName) { ")\n" + "PARTITION BY ( year, dt )\n" + "PROPERTIES (\"location\" = \"hdfs://hadoop/hive/warehouse/test.db/test\");", resultSet.getResultRows().get(0).get(1)); +======= + " `id` int(11) DEFAULT NULL COMMENT \"id\",\n" + + " `name` varchar DEFAULT NULL,\n" + + " `year` int(11) DEFAULT NULL,\n" + + " `dt` int(11) DEFAULT NULL\n" + + ")\n" + + "PARTITION BY (year, dt)\n" + + "PROPERTIES (\"location\" = \"hdfs://hadoop/hive/warehouse/test.db/test\");", + resultSet.getResultRows().get(0).get(1)); + } + + @Test + public void testShowCreateHiveExternalTable() { + new MockUp() { + @Mock + public Database getDb(String catalogName, String dbName) { + return new Database(); + } + + @Mock + public Table getTable(String catalogName, String dbName, String tblName) { + List fullSchema = new ArrayList<>(); + Column columnId = new Column("id", Type.INT, true); + columnId.setComment("id"); + Column columnName = new Column("name", Type.VARCHAR); + Column columnYear = new Column("year", Type.INT); + Column columnDt = new Column("dt", Type.INT); + fullSchema.add(columnId); + fullSchema.add(columnName); + fullSchema.add(columnYear); + fullSchema.add(columnDt); + List partitions = Lists.newArrayList(); + partitions.add("year"); + partitions.add("dt"); + HiveTable.Builder tableBuilder = HiveTable.builder() + .setId(1) + .setTableName("test_table") + .setCatalogName("hive_catalog") + .setResourceName(toResourceName("hive_catalog", "hive")) + .setHiveDbName("hive_db") + .setHiveTableName("test_table") + .setPartitionColumnNames(partitions) + .setFullSchema(fullSchema) + .setTableLocation("hdfs://hadoop/hive/warehouse/test.db/test") + .setCreateTime(10000) + .setHiveTableType(HiveTable.HiveTableType.EXTERNAL_TABLE); + return tableBuilder.build(); + } + }; + + ShowCreateTableStmt stmt = new ShowCreateTableStmt(new TableName("hive_catalog", "hive_db", "test_table"), + ShowCreateTableStmt.CreateTableType.TABLE); + + ShowResultSet resultSet = ShowExecutor.execute(stmt, ctx); + Assert.assertEquals("test_table", resultSet.getResultRows().get(0).get(0)); + Assert.assertEquals("CREATE EXTERNAL TABLE `test_table` (\n" + + " `id` int(11) DEFAULT NULL COMMENT \"id\",\n" + + " `name` varchar DEFAULT NULL,\n" + + " `year` int(11) DEFAULT NULL,\n" + + " `dt` int(11) DEFAULT NULL\n" + + ")\n" + + "PARTITION BY (year, dt)\n" + + "PROPERTIES (\"location\" = \"hdfs://hadoop/hive/warehouse/test.db/test\");", + resultSet.getResultRows().get(0).get(1)); +>>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) } @Test diff --git a/test/sql/test_iceberg/R/test_iceberg_show_stmt b/test/sql/test_iceberg/R/test_iceberg_show_stmt new file mode 100644 index 0000000000000..0759ccc86433d --- /dev/null +++ b/test/sql/test_iceberg/R/test_iceberg_show_stmt @@ -0,0 +1,21 @@ +-- name: test_iceberg_show_stmt +create external catalog iceberg_sql_test_${uuid0} PROPERTIES ("type"="iceberg", "iceberg.catalog.type"="hive", "iceberg.catalog.hive.metastore.uris"="${iceberg_catalog_hive_metastore_uris}","enable_iceberg_metadata_cache"="true","aws.s3.access_key" = "${oss_ak}","aws.s3.secret_key" = "${oss_sk}","aws.s3.endpoint" = "${oss_endpoint}"); +-- result: +-- !result +show create table iceberg_sql_test_${uuid0}.iceberg_ci_db.partition_transform_table; +-- result: +partition_transform_table CREATE TABLE `partition_transform_table` ( + `k1` int(11) DEFAULT NULL, + `t1` datetime DEFAULT NULL, + `t2` datetime DEFAULT NULL, + `t3` datetime DEFAULT NULL, + `t4` datetime DEFAULT NULL, + `p1` varchar(1073741824) DEFAULT NULL, + `p2` varchar(1073741824) DEFAULT NULL +) +PARTITION BY (year(t1), month(t2), day(t3), hour(t4), truncate(p1, 5), bucket(p2, 3)) +PROPERTIES ("location" = "oss://starrocks-ci-test/iceberg_ci_db/partition_transform_table"); +-- !result +drop catalog iceberg_sql_test_${uuid0}; +-- result: +-- !result \ No newline at end of file diff --git a/test/sql/test_iceberg/T/test_iceberg_show_stmt b/test/sql/test_iceberg/T/test_iceberg_show_stmt new file mode 100644 index 0000000000000..71cb29293424d --- /dev/null +++ b/test/sql/test_iceberg/T/test_iceberg_show_stmt @@ -0,0 +1,7 @@ +-- name: test_iceberg_show_stmt + +create external catalog iceberg_sql_test_${uuid0} PROPERTIES ("type"="iceberg", "iceberg.catalog.type"="hive", "iceberg.catalog.hive.metastore.uris"="${iceberg_catalog_hive_metastore_uris}","enable_iceberg_metadata_cache"="true","aws.s3.access_key" = "${oss_ak}","aws.s3.secret_key" = "${oss_sk}","aws.s3.endpoint" = "${oss_endpoint}"); + +show create table iceberg_sql_test_${uuid0}.iceberg_ci_db.partition_transform_table; + +drop catalog iceberg_sql_test_${uuid0}; From e549ffc43712252d494b7fc15c7737edeaac4b8e Mon Sep 17 00:00:00 2001 From: stephen Date: Thu, 8 Aug 2024 19:00:40 +0800 Subject: [PATCH 2/3] fix conflict Signed-off-by: stephen --- .../com/starrocks/catalog/IcebergTable.java | 12 ---- .../iceberg/IcebergApiConverter.java | 56 --------------- .../com/starrocks/qe/ShowExecutorTest.java | 68 +------------------ 3 files changed, 1 insertion(+), 135 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java b/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java index 65751e491259c..cb83f3b15c1ce 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/IcebergTable.java @@ -324,19 +324,7 @@ public org.apache.iceberg.Table getNativeTable() { } return nativeTable; } -<<<<<<< HEAD - public long getRefreshSnapshotTime() { - return refreshSnapshotTime; - } - - public void setRefreshSnapshotTime(long refreshSnapshotTime) { - this.refreshSnapshotTime = refreshSnapshotTime; - } - -======= - ->>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) public void setIdentifierFieldIds(Set identifierFieldIds) { this.identifierFieldIds = identifierFieldIds; } diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java b/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java index 56167c46abab1..b207d2b1ffc1b 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergApiConverter.java @@ -51,12 +51,8 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -<<<<<<< HEAD -======= import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; ->>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) import static com.google.common.collect.ImmutableList.toImmutableList; import static com.starrocks.analysis.OutFileClause.PARQUET_COMPRESSION_TYPE_MAP; @@ -64,11 +60,7 @@ import static com.starrocks.connector.ConnectorTableId.CONNECTOR_ID_GENERATOR; import static com.starrocks.connector.iceberg.IcebergConnector.ICEBERG_CATALOG_TYPE; import static com.starrocks.server.CatalogMgr.ResourceMappingCatalog.toResourceName; -<<<<<<< HEAD -======= import static java.lang.String.format; -import static org.apache.iceberg.view.ViewProperties.COMMENT; ->>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) public class IcebergApiConverter { private static final Logger LOG = LogManager.getLogger(IcebergApiConverter.class); @@ -308,53 +300,6 @@ public static Map rebuildCreateTableProperties(Map filterManifests(List manifests, - org.apache.iceberg.Table table, Expression filter) { - Map evalCache = specCache(table, filter); - - return manifests.stream() - .filter(manifest -> manifest.hasAddedFiles() || manifest.hasExistingFiles()) - .filter(manifest -> evalCache.get(manifest.partitionSpecId()).eval(manifest)) - .collect(Collectors.toList()); - } - - private static Map specCache(org.apache.iceberg.Table table, Expression filter) { - Map cache = new ConcurrentHashMap<>(); - - for (Map.Entry entry : table.specs().entrySet()) { - Integer spedId = entry.getKey(); - PartitionSpec spec = entry.getValue(); - - Expression projection = Projections.inclusive(spec, false).project(filter); - ManifestEvaluator evaluator = ManifestEvaluator.forPartitionFilter(projection, spec, false); - - cache.put(spedId, evaluator); - } - return cache; - } - - public static boolean mayHaveEqualityDeletes(Snapshot snapshot) { - String count = snapshot.summary().get(SnapshotSummary.TOTAL_EQ_DELETES_PROP); - return count == null || !count.equals("0"); - } - - public static IcebergView toView(String catalogName, String dbName, View icebergView) { - SQLViewRepresentation sqlView = icebergView.sqlFor("starrocks"); - String comment = icebergView.properties().get(COMMENT); - List columns = toFullSchemas(icebergView.schema()); - ViewVersion currentVersion = icebergView.currentVersion(); - String defaultCatalogName = currentVersion.defaultCatalog(); - String defaultDbName = currentVersion.defaultNamespace().level(0); - String viewName = icebergView.name(); - String location = icebergView.location(); - IcebergView view = new IcebergView(CONNECTOR_ID_GENERATOR.getNextId().asInt(), catalogName, dbName, viewName, - columns, sqlView.sql(), defaultCatalogName, defaultDbName, location); - view.setComment(comment); - return view; - } public static List toPartitionFields(PartitionSpec spec) { return spec.fields().stream() @@ -389,5 +334,4 @@ private static String toPartitionField(PartitionSpec spec, PartitionField field) throw new StarRocksConnectorException("Unsupported partition transform: " + field); } ->>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) } \ No newline at end of file diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java index b06dff908c2e6..06fedfc95aad1 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java @@ -1088,79 +1088,13 @@ public Table getTable(String catalogName, String dbName, String tblName) { ShowResultSet resultSet = executor.execute(); Assert.assertEquals("test_table", resultSet.getResultRows().get(0).get(0)); Assert.assertEquals("CREATE TABLE `test_table` (\n" + -<<<<<<< HEAD " `id` int(11) DEFAULT NULL COMMENT \"id\",\n" + " `name` varchar DEFAULT NULL,\n" + " `year` int(11) DEFAULT NULL,\n" + " `dt` int(11) DEFAULT NULL\n" + ")\n" + - "PARTITION BY ( year, dt )\n" + + "PARTITION BY (year, dt)\n" + "PROPERTIES (\"location\" = \"hdfs://hadoop/hive/warehouse/test.db/test\");", resultSet.getResultRows().get(0).get(1)); -======= - " `id` int(11) DEFAULT NULL COMMENT \"id\",\n" + - " `name` varchar DEFAULT NULL,\n" + - " `year` int(11) DEFAULT NULL,\n" + - " `dt` int(11) DEFAULT NULL\n" + - ")\n" + - "PARTITION BY (year, dt)\n" + - "PROPERTIES (\"location\" = \"hdfs://hadoop/hive/warehouse/test.db/test\");", - resultSet.getResultRows().get(0).get(1)); - } - - @Test - public void testShowCreateHiveExternalTable() { - new MockUp() { - @Mock - public Database getDb(String catalogName, String dbName) { - return new Database(); - } - - @Mock - public Table getTable(String catalogName, String dbName, String tblName) { - List fullSchema = new ArrayList<>(); - Column columnId = new Column("id", Type.INT, true); - columnId.setComment("id"); - Column columnName = new Column("name", Type.VARCHAR); - Column columnYear = new Column("year", Type.INT); - Column columnDt = new Column("dt", Type.INT); - fullSchema.add(columnId); - fullSchema.add(columnName); - fullSchema.add(columnYear); - fullSchema.add(columnDt); - List partitions = Lists.newArrayList(); - partitions.add("year"); - partitions.add("dt"); - HiveTable.Builder tableBuilder = HiveTable.builder() - .setId(1) - .setTableName("test_table") - .setCatalogName("hive_catalog") - .setResourceName(toResourceName("hive_catalog", "hive")) - .setHiveDbName("hive_db") - .setHiveTableName("test_table") - .setPartitionColumnNames(partitions) - .setFullSchema(fullSchema) - .setTableLocation("hdfs://hadoop/hive/warehouse/test.db/test") - .setCreateTime(10000) - .setHiveTableType(HiveTable.HiveTableType.EXTERNAL_TABLE); - return tableBuilder.build(); - } - }; - - ShowCreateTableStmt stmt = new ShowCreateTableStmt(new TableName("hive_catalog", "hive_db", "test_table"), - ShowCreateTableStmt.CreateTableType.TABLE); - - ShowResultSet resultSet = ShowExecutor.execute(stmt, ctx); - Assert.assertEquals("test_table", resultSet.getResultRows().get(0).get(0)); - Assert.assertEquals("CREATE EXTERNAL TABLE `test_table` (\n" + - " `id` int(11) DEFAULT NULL COMMENT \"id\",\n" + - " `name` varchar DEFAULT NULL,\n" + - " `year` int(11) DEFAULT NULL,\n" + - " `dt` int(11) DEFAULT NULL\n" + - ")\n" + - "PARTITION BY (year, dt)\n" + - "PROPERTIES (\"location\" = \"hdfs://hadoop/hive/warehouse/test.db/test\");", - resultSet.getResultRows().get(0).get(1)); ->>>>>>> 4855c19b37 ([Enhancement] desc iceberg table with transform type (#49094)) } @Test From bfe04eae2da942cf1daf095367161d1c6dc915cd Mon Sep 17 00:00:00 2001 From: stephen Date: Thu, 8 Aug 2024 19:13:49 +0800 Subject: [PATCH 3/3] fix compile Signed-off-by: stephen --- .../main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java index bc5857d7ed9c3..d45f3362c3bab 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AstToStringBuilder.java @@ -57,6 +57,7 @@ import com.starrocks.catalog.HiveMetaStoreTable; import com.starrocks.catalog.HiveTable; import com.starrocks.catalog.HiveView; +import com.starrocks.catalog.IcebergTable; import com.starrocks.catalog.Table; import com.starrocks.common.Pair; import com.starrocks.common.util.ParseUtil;