This is an automated email from the ASF dual-hosted git repository. lzljs3620320 pushed a commit to branch release-0.8 in repository https://gitbox.apache.org/repos/asf/paimon.git
commit 45be92ac2f236aadac93debc6d6e80c6d59f242b Author: juncheng yin <[email protected]> AuthorDate: Sun May 12 23:00:59 2024 +0800 [hive] fix db-location conflict with location-in-properties (#3309) --- .../paimon/hive/TBPropertiesLocationHelper.java | 1 + .../apache/paimon/hive/HiveCatalogITCaseBase.java | 39 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/TBPropertiesLocationHelper.java b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/TBPropertiesLocationHelper.java index 8f4ceee6d..c4fe2a94b 100644 --- a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/TBPropertiesLocationHelper.java +++ b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/TBPropertiesLocationHelper.java @@ -69,6 +69,7 @@ public final class TBPropertiesLocationHelper implements LocationHelper { } properties.put(LocationKeyExtractor.TBPROPERTIES_LOCATION_KEY, path.toString()); database.setParameters(properties); + database.setLocationUri(null); } @Override diff --git a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java index a5c494c1e..e478d44cd 100644 --- a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java +++ b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java @@ -42,6 +42,7 @@ import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException; import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException; import org.apache.flink.types.Row; import org.apache.flink.util.CloseableIterator; +import org.apache.hadoop.hive.metastore.api.MetaException; import org.junit.Rule; import org.junit.Test; import org.junit.jupiter.api.function.Executable; @@ -159,6 +160,44 @@ public abstract class HiveCatalogITCaseBase { } }; + @Test + public void testDbLocation() { + String dbLocation = minioTestContainer.getS3UriForDefaultBucket() + "/" + UUID.randomUUID(); + Catalog catalog = + ((FlinkCatalog) tEnv.getCatalog(tEnv.getCurrentCatalog()).get()).catalog(); + Map<String, String> properties = new HashMap<>(); + properties.put("location", dbLocation); + + assertThatThrownBy(() -> catalog.createDatabase("location_test_db", false, properties)) + .hasRootCauseInstanceOf(MetaException.class) + .hasRootCauseMessage( + "Got exception: java.io.IOException No FileSystem for scheme: s3"); + } + + @Test + @LocationInProperties + public void testDbLocationWithMetastoreLocationInProperties() + throws Catalog.DatabaseAlreadyExistException { + String dbLocation = minioTestContainer.getS3UriForDefaultBucket() + "/" + UUID.randomUUID(); + Catalog catalog = + ((FlinkCatalog) tEnv.getCatalog(tEnv.getCurrentCatalog()).get()).catalog(); + Map<String, String> properties = new HashMap<>(); + properties.put("location", dbLocation); + + catalog.createDatabase("location_test_db", false, properties); + assertThat(catalog.databaseExists("location_test_db")); + + hiveShell.execute("USE location_test_db"); + hiveShell.execute("CREATE TABLE location_test_db ( a INT, b INT )"); + hiveShell.execute("INSERT INTO location_test_db VALUES (1, 100)"); + hiveShell.execute("INSERT INTO location_test_db VALUES (2, 200)"); + + assertThat(hiveShell.executeQuery("SELECT * from location_test_db")) + .containsExactlyInAnyOrder("1\t100", "2\t200"); + + hiveShell.execute("DROP DATABASE IF EXISTS location_test_db CASCADE"); + } + @Test public void testDatabaseOperations() throws Exception { // create database
