diff --git a/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java b/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java index 239162e8b9f7..e932075eab0d 100644 --- a/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java +++ b/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java @@ -249,12 +249,6 @@ void testCommentOnView() assertUpdate("DROP VIEW " + viewName); } - private String getTableComment(String tableName) - { - return (String) computeScalar("SELECT comment FROM system.metadata.table_comments " + - "WHERE catalog_name = CURRENT_CATALOG AND schema_name = CURRENT_SCHEMA AND table_name = '" + tableName + "'"); - } - @Test void testFieldLength() { diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeRegisterTableProcedureTest.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeRegisterTableProcedureTest.java index 471b6c212d62..9a849a68509c 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeRegisterTableProcedureTest.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeRegisterTableProcedureTest.java @@ -319,13 +319,6 @@ protected String getTableLocation(String tableName) throw new IllegalStateException("Location not found in SHOW CREATE TABLE result"); } - private String getTableComment(String tableName) - { - return (String) computeScalar(format( - "SELECT comment FROM system.metadata.table_comments WHERE catalog_name = CURRENT_CATALOG AND schema_name = CURRENT_SCHEMA AND table_name = '%s'", - tableName)); - } - protected HiveMetastore metastore() { return TestingDeltaLakeUtils.getConnectorService(getQueryRunner(), HiveMetastoreFactory.class) diff --git a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java index 0e3be1ef747f..ea2c00c81773 100644 --- a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java +++ b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java @@ -15,6 +15,7 @@ package io.trino.plugin.faker; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.errorprone.annotations.concurrent.GuardedBy; import io.airlift.slice.Slice; import io.trino.spi.TrinoException; @@ -59,8 +60,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; import static com.google.common.base.Verify.verify; import static com.google.common.collect.ImmutableList.toImmutableList; @@ -223,8 +222,9 @@ public synchronized void renameTable(ConnectorSession session, ConnectorTableHan FakerTableHandle handle = (FakerTableHandle) tableHandle; SchemaTableName oldTableName = handle.schemaTableName(); + TableInfo oldInfo = tables.get(oldTableName); tables.remove(oldTableName); - tables.put(newTableName, tables.get(oldTableName)); + tables.put(newTableName, oldInfo); } @Override @@ -234,13 +234,18 @@ public synchronized void setTableProperties(ConnectorSession session, ConnectorT SchemaTableName tableName = handle.schemaTableName(); TableInfo oldInfo = tables.get(tableName); - Map newProperties = Stream.concat( - oldInfo.properties().entrySet().stream() - .filter(entry -> !properties.containsKey(entry.getKey())), - properties.entrySet().stream() - .filter(entry -> entry.getValue().isPresent())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - tables.put(tableName, oldInfo.withProperties(newProperties)); + ImmutableMap.Builder updatedProperties = ImmutableMap.builder().putAll(oldInfo.properties()); + if (properties.containsKey(TableInfo.NULL_PROBABILITY_PROPERTY)) { + double nullProbability = (double) properties.get(TableInfo.NULL_PROBABILITY_PROPERTY) + .orElseThrow(() -> new IllegalArgumentException("The null_probability property cannot be empty")); + updatedProperties.put(TableInfo.NULL_PROBABILITY_PROPERTY, nullProbability); + } + if (properties.containsKey(TableInfo.DEFAULT_LIMIT_PROPERTY)) { + long defaultLimit = (long) properties.get(TableInfo.DEFAULT_LIMIT_PROPERTY) + .orElseThrow(() -> new IllegalArgumentException("The default_limit property cannot be empty")); + updatedProperties.put(TableInfo.DEFAULT_LIMIT_PROPERTY, defaultLimit); + } + tables.put(tableName, oldInfo.withProperties(updatedProperties.buildOrThrow())); } @Override diff --git a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java index cb75ebaeb777..ea2ab318d56d 100644 --- a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java +++ b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java @@ -850,4 +850,32 @@ AND rnd_uuid IN (UUID '1fc74d96-0216-449b-a145-455578a9eaa5', UUID '3ee49ede-002 assertUpdate("DROP TABLE faker.default.all_types_in"); } + + @Test + void testRenameTable() + { + assertUpdate("CREATE TABLE faker.default.original_table (id INTEGER, name VARCHAR)"); + assertUpdate("ALTER TABLE faker.default.original_table RENAME TO faker.default.renamed_table"); + assertUpdate("DROP TABLE faker.default.renamed_table"); + } + + @Test + void testSetTableProperties() + { + try (TestTable table = new TestTable(getQueryRunner()::execute, "set_table_properties", "(id INTEGER, name VARCHAR)")) { + assertUpdate("ALTER TABLE %s SET PROPERTIES default_limit = 100".formatted(table.getName())); + assertQueryFails("ALTER TABLE %s SET PROPERTIES invalid_property = true".formatted(table.getName()), "(?s).*Catalog 'faker' table property 'invalid_property' does not exist"); + assertThat((String) computeScalar("SHOW CREATE TABLE " + table.getName())) + .contains("default_limit = 100"); + } + } + + @Test + void testTableComment() + { + try (TestTable table = new TestTable(getQueryRunner()::execute, "table_comment", "(id INTEGER, name VARCHAR)")) { + assertUpdate("COMMENT ON TABLE %s IS 'this is a test table'".formatted(table.getName())); + assertThat(getTableComment(table.getName())).isEqualTo("this is a test table"); + } + } } diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java index c95aed097d36..38271aff2090 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java @@ -575,11 +575,6 @@ private void dropTableFromMetastore(String tableName) assertThat(metastore.getTable(getSession().getSchema().orElseThrow(), tableName)).as("Table in metastore should be dropped").isEmpty(); } - private String getTableComment(String tableName) - { - return (String) computeScalar("SELECT comment FROM system.metadata.table_comments WHERE catalog_name = 'iceberg' AND schema_name = '" + getSession().getSchema().orElseThrow() + "' AND table_name = '" + tableName + "'"); - } - private String getColumnComment(String tableName, String columnName) { return (String) computeScalar("SELECT comment FROM information_schema.columns WHERE table_schema = '" + getSession().getSchema().orElseThrow() + "' AND table_name = '" + tableName + "' AND column_name = '" + columnName + "'"); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/rest/TestIcebergPolarisCatalogCaseInsensitiveMapping.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/rest/TestIcebergPolarisCatalogCaseInsensitiveMapping.java index 2267cc46dac2..b84c0401a1b8 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/rest/TestIcebergPolarisCatalogCaseInsensitiveMapping.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/rest/TestIcebergPolarisCatalogCaseInsensitiveMapping.java @@ -255,12 +255,6 @@ void testCaseInsensitiveMatchingForView() assertQueryFails("SELECT * FROM " + viewName2, ".*'iceberg.%s.%s' does not exist".formatted(LOWERCASE_SCHEMA, lowercaseViewName2)); } - private String getTableComment(String tableName) - { - return (String) computeScalar("SELECT comment FROM system.metadata.table_comments " + - "WHERE catalog_name = 'iceberg' AND schema_name = '" + LOWERCASE_SCHEMA + "' AND table_name = '" + tableName + "'"); - } - private String getColumnComment(String tableName, String columnName) { return (String) computeScalar("SELECT comment FROM information_schema.columns " + diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/procedure/TestIcebergMigrateProcedure.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/procedure/TestIcebergMigrateProcedure.java index 6fd0923954c7..311f4fc897c0 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/procedure/TestIcebergMigrateProcedure.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/procedure/TestIcebergMigrateProcedure.java @@ -436,11 +436,6 @@ public void testMigrateTablePreserveComments() assertUpdate("DROP TABLE " + tableName); } - private String getTableComment(String tableName) - { - return (String) computeScalar("SELECT comment FROM system.metadata.table_comments WHERE catalog_name = 'iceberg' AND schema_name = 'tpch' AND table_name = '" + tableName + "'"); - } - private String getColumnComment(String tableName, String columnName) { return (String) computeScalar("SELECT comment FROM information_schema.columns WHERE table_catalog = 'iceberg' AND table_schema = 'tpch' AND table_name = '" + tableName + "' AND column_name = '" + columnName + "'"); diff --git a/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java b/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java index 2517e923d4d1..d6f6ad4a0dde 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java @@ -743,6 +743,22 @@ private CatalogSchemaTableName getTableName(TableHandle tableHandle) }); } + protected String getTableComment(String tableName) + { + return getTableComment(getSession(), tableName); + } + + protected String getTableComment(Session session, String tableName) + { + return getTableComment(session.getCatalog().orElseThrow(), session.getSchema().orElseThrow(), tableName); + } + + protected String getTableComment(String catalogName, String schemaName, String tableName) + { + String sql = format("SELECT comment FROM system.metadata.table_comments WHERE catalog_name = '%s' AND schema_name = '%s' AND table_name = '%s'", catalogName, schemaName, tableName); + return (String) computeScalar(sql); + } + private T inTransaction(Session session, Function transactionSessionConsumer) { return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getPlannerContext().getMetadata(), getQueryRunner().getAccessControl()) diff --git a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorSmokeTest.java b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorSmokeTest.java index b491e6ab375c..6ed60caccea6 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorSmokeTest.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorSmokeTest.java @@ -742,11 +742,6 @@ public void testCommentMaterializedViewColumn() } } - protected String getTableComment(String tableName) - { - return (String) computeScalar(format("SELECT comment FROM system.metadata.table_comments WHERE catalog_name = '%s' AND schema_name = '%s' AND table_name = '%s'", getSession().getCatalog().orElseThrow(), getSession().getSchema().orElseThrow(), tableName)); - } - protected String getColumnComment(String tableName, String columnName) { return (String) computeScalar(format( diff --git a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java index c9fbbc3bffa3..1df1a95a7c63 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java @@ -4252,12 +4252,6 @@ public void testCommentTable() } } - protected String getTableComment(String catalogName, String schemaName, String tableName) - { - String sql = format("SELECT comment FROM system.metadata.table_comments WHERE catalog_name = '%s' AND schema_name = '%s' AND table_name = '%s'", catalogName, schemaName, tableName); - return (String) computeScalar(sql); - } - @Test public void testCommentView() {