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 34a619fe5 [core] Rename some methods of AbstractCatalog for location
34a619fe5 is described below

commit 34a619fe56a3d3f8ada008cc1b5c62c3c6c684ec
Author: Jingsong <[email protected]>
AuthorDate: Mon Nov 27 22:08:52 2023 +0800

    [core] Rename some methods of AbstractCatalog for location
---
 .../org/apache/paimon/catalog/AbstractCatalog.java   | 17 ++++++++---------
 .../org/apache/paimon/catalog/FileSystemCatalog.java |  8 ++++----
 .../java/org/apache/paimon/hive/HiveCatalog.java     | 20 ++++++++++----------
 .../java/org/apache/paimon/hive/PaimonMetaHook.java  |  2 +-
 .../org/apache/paimon/hive/CreateTableITCase.java    | 18 +++++++++---------
 .../org/apache/paimon/hive/HiveLocationTest.java     |  4 ++--
 6 files changed, 34 insertions(+), 35 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java 
b/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java
index 93e41ff68..a54ea924d 100644
--- a/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java
@@ -295,8 +295,8 @@ public abstract class AbstractCatalog implements Catalog {
     }
 
     @VisibleForTesting
-    public Path databasePath(String database) {
-        return databasePath(warehouse(), database);
+    public Path newDatabasePath(String database) {
+        return newDatabasePath(warehouse(), database);
     }
 
     Map<String, Map<String, Path>> allTablePaths() {
@@ -306,9 +306,7 @@ public abstract class AbstractCatalog implements Catalog {
                 Map<String, Path> tableMap =
                         allPaths.computeIfAbsent(database, d -> new 
HashMap<>());
                 for (String table : listTables(database)) {
-                    tableMap.put(
-                            table,
-                            dataTableLocation(warehouse(), 
Identifier.create(database, table)));
+                    tableMap.put(table, 
getDataTableLocation(Identifier.create(database, table)));
                 }
             }
             return allPaths;
@@ -328,7 +326,7 @@ public abstract class AbstractCatalog implements Catalog {
 
     @VisibleForTesting
     public Path getDataTableLocation(Identifier identifier) {
-        return dataTableLocation(warehouse(), identifier);
+        return newTableLocation(warehouse(), identifier);
     }
 
     private static boolean isSpecifiedSystemTable(Identifier identifier) {
@@ -362,7 +360,7 @@ public abstract class AbstractCatalog implements Catalog {
         return splits;
     }
 
-    public static Path dataTableLocation(String warehouse, Identifier 
identifier) {
+    public static Path newTableLocation(String warehouse, Identifier 
identifier) {
         if (isSpecifiedSystemTable(identifier)) {
             throw new IllegalArgumentException(
                     String.format(
@@ -370,10 +368,11 @@ public abstract class AbstractCatalog implements Catalog {
                             identifier.getObjectName(), 
SYSTEM_TABLE_SPLITTER));
         }
         return new Path(
-                databasePath(warehouse, identifier.getDatabaseName()), 
identifier.getObjectName());
+                newDatabasePath(warehouse, identifier.getDatabaseName()),
+                identifier.getObjectName());
     }
 
-    public static Path databasePath(String warehouse, String database) {
+    public static Path newDatabasePath(String warehouse, String database) {
         return new Path(warehouse, database + DB_SUFFIX);
     }
 
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java 
b/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java
index 3912c3e36..03523da58 100644
--- a/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java
@@ -68,23 +68,23 @@ public class FileSystemCatalog extends AbstractCatalog {
 
     @Override
     protected boolean databaseExistsImpl(String databaseName) {
-        return uncheck(() -> fileIO.exists(databasePath(databaseName)));
+        return uncheck(() -> fileIO.exists(newDatabasePath(databaseName)));
     }
 
     @Override
     protected void createDatabaseImpl(String name) {
-        uncheck(() -> fileIO.mkdirs(databasePath(name)));
+        uncheck(() -> fileIO.mkdirs(newDatabasePath(name)));
     }
 
     @Override
     protected void dropDatabaseImpl(String name) {
-        uncheck(() -> fileIO.delete(databasePath(name), true));
+        uncheck(() -> fileIO.delete(newDatabasePath(name), true));
     }
 
     @Override
     protected List<String> listTablesImpl(String databaseName) {
         List<String> tables = new ArrayList<>();
-        for (FileStatus status : uncheck(() -> 
fileIO.listStatus(databasePath(databaseName)))) {
+        for (FileStatus status : uncheck(() -> 
fileIO.listStatus(newDatabasePath(databaseName)))) {
             if (status.isDir() && tableExists(status.getPath())) {
                 tables.add(status.getPath().getName());
             }
diff --git 
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
index d67911bbc..987ec2c7c 100644
--- 
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
+++ 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
@@ -208,8 +208,13 @@ public class HiveCatalog extends AbstractCatalog {
     @Override
     protected void createDatabaseImpl(String name) {
         try {
-            client.createDatabase(convertToDatabase(name));
-            locationHelper.createPathIfRequired(databasePath(name), fileIO);
+            Path databasePath = newDatabasePath(name);
+            locationHelper.createPathIfRequired(databasePath, fileIO);
+
+            Database database = new Database();
+            database.setName(name);
+            locationHelper.specifyDatabaseLocation(databasePath, database);
+            client.createDatabase(database);
         } catch (TException | IOException e) {
             throw new RuntimeException("Failed to create database " + name, e);
         }
@@ -218,7 +223,9 @@ public class HiveCatalog extends AbstractCatalog {
     @Override
     protected void dropDatabaseImpl(String name) {
         try {
-            locationHelper.dropPathIfRequired(databasePath(name), fileIO);
+            Database database = client.getDatabase(name);
+            String location = locationHelper.getDatabaseLocation(database);
+            locationHelper.dropPathIfRequired(new Path(location), fileIO);
             client.dropDatabase(name, true, false, true);
         } catch (TException | IOException e) {
             throw new RuntimeException("Failed to drop database " + name, e);
@@ -421,13 +428,6 @@ public class HiveCatalog extends AbstractCatalog {
                         identifier.getObjectName()));
     }
 
-    private Database convertToDatabase(String name) {
-        Database database = new Database();
-        database.setName(name);
-        locationHelper.specifyDatabaseLocation(databasePath(name), database);
-        return database;
-    }
-
     private Table newHmsTable(Identifier identifier, Map<String, String> 
tableParameters) {
         long currentTimeMillis = System.currentTimeMillis();
         TableType tableType =
diff --git 
a/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/PaimonMetaHook.java
 
b/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/PaimonMetaHook.java
index 97e7bfcfd..281d2091b 100644
--- 
a/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/PaimonMetaHook.java
+++ 
b/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/PaimonMetaHook.java
@@ -87,7 +87,7 @@ public class PaimonMetaHook implements HiveMetaHook {
             org.apache.hadoop.fs.Path hadoopPath =
                     getDnsPath(new org.apache.hadoop.fs.Path(warehouse), conf);
             warehouse = hadoopPath.toUri().toString();
-            location = AbstractCatalog.dataTableLocation(warehouse, 
identifier).toUri().toString();
+            location = AbstractCatalog.newTableLocation(warehouse, 
identifier).toUri().toString();
             table.getSd().setLocation(location);
         }
 
diff --git 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/CreateTableITCase.java
 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/CreateTableITCase.java
index f861ee0f4..e04cd00eb 100644
--- 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/CreateTableITCase.java
+++ 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/CreateTableITCase.java
@@ -94,7 +94,7 @@ public class CreateTableITCase extends HiveTestBase {
                         Maps.newHashMap(),
                         "");
         Identifier identifier = Identifier.create(DATABASE_TEST, tableName);
-        Path tablePath = AbstractCatalog.dataTableLocation(path, identifier);
+        Path tablePath = AbstractCatalog.newTableLocation(path, identifier);
         new SchemaManager(LocalFileIO.create(), tablePath).createTable(schema);
 
         // Create hive external table
@@ -156,7 +156,7 @@ public class CreateTableITCase extends HiveTestBase {
 
         // check the paimon table schema
         Identifier identifier = Identifier.create(DATABASE_TEST, tableName);
-        Path tablePath = AbstractCatalog.dataTableLocation(path, identifier);
+        Path tablePath = AbstractCatalog.newTableLocation(path, identifier);
         Optional<TableSchema> tableSchema =
                 new SchemaManager(LocalFileIO.create(), tablePath).latest();
         assertThat(tableSchema).isPresent();
@@ -212,7 +212,7 @@ public class CreateTableITCase extends HiveTestBase {
         }
         // check the paimon table name and schema
         Identifier identifier = Identifier.create(DATABASE_TEST, 
tableName.toLowerCase());
-        Path tablePath = AbstractCatalog.dataTableLocation(path, identifier);
+        Path tablePath = AbstractCatalog.newTableLocation(path, identifier);
         Options conf = new Options();
         conf.set(CatalogOptions.WAREHOUSE, path);
         CatalogContext catalogContext = CatalogContext.create(conf);
@@ -277,7 +277,7 @@ public class CreateTableITCase extends HiveTestBase {
 
         // check the paimon db name态table name and schema
         Identifier identifier = Identifier.create(upperDB.toLowerCase(), 
tableName.toLowerCase());
-        Path tablePath = AbstractCatalog.dataTableLocation(path, identifier);
+        Path tablePath = AbstractCatalog.newTableLocation(path, identifier);
         Options conf = new Options();
         conf.set(CatalogOptions.WAREHOUSE, path);
         CatalogContext catalogContext = CatalogContext.create(conf);
@@ -322,7 +322,7 @@ public class CreateTableITCase extends HiveTestBase {
 
         // check the paimon table schema
         Identifier identifier = Identifier.create(DATABASE_TEST, tableName);
-        Path tablePath = AbstractCatalog.dataTableLocation(path, identifier);
+        Path tablePath = AbstractCatalog.newTableLocation(path, identifier);
         Optional<TableSchema> tableSchema =
                 new SchemaManager(LocalFileIO.create(), tablePath).latest();
         assertThat(tableSchema).isPresent();
@@ -364,7 +364,7 @@ public class CreateTableITCase extends HiveTestBase {
 
         // check the paimon table schema
         Identifier identifier = Identifier.create(DATABASE_TEST, tableName);
-        Path tablePath = AbstractCatalog.dataTableLocation(path, identifier);
+        Path tablePath = AbstractCatalog.newTableLocation(path, identifier);
         Optional<TableSchema> tableSchema =
                 new SchemaManager(LocalFileIO.create(), tablePath).latest();
         assertThat(tableSchema).isPresent();
@@ -408,7 +408,7 @@ public class CreateTableITCase extends HiveTestBase {
 
         // check the paimon table schema
         Identifier identifier = Identifier.create(DATABASE_TEST, tableName);
-        Path tablePath = AbstractCatalog.dataTableLocation(path, identifier);
+        Path tablePath = AbstractCatalog.newTableLocation(path, identifier);
         Optional<TableSchema> tableSchema =
                 new SchemaManager(LocalFileIO.create(), tablePath).latest();
         assertThat(tableSchema).isPresent();
@@ -456,7 +456,7 @@ public class CreateTableITCase extends HiveTestBase {
                             Maps.newHashMap(),
                             "");
             Identifier identifier = Identifier.create(DATABASE_TEST, 
tableName);
-            Path tablePath = AbstractCatalog.dataTableLocation(path, 
identifier);
+            Path tablePath = AbstractCatalog.newTableLocation(path, 
identifier);
             new SchemaManager(LocalFileIO.create(), 
tablePath).createTable(schema);
 
             String hiveSql =
@@ -500,7 +500,7 @@ public class CreateTableITCase extends HiveTestBase {
             } catch (Exception ignore) {
             } finally {
                 Identifier identifier = Identifier.create(DATABASE_TEST, 
tableName);
-                Path tablePath = AbstractCatalog.dataTableLocation(path, 
identifier);
+                Path tablePath = AbstractCatalog.newTableLocation(path, 
identifier);
                 boolean isPresent =
                         new SchemaManager(LocalFileIO.create(), 
tablePath).latest().isPresent();
                 Assertions.assertThat(isPresent).isFalse();
diff --git 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveLocationTest.java
 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveLocationTest.java
index 45f3d4a0b..6a323eabc 100644
--- 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveLocationTest.java
+++ 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveLocationTest.java
@@ -147,7 +147,7 @@ public class HiveLocationTest {
             catalog.createDatabase(db, true);
             assertThat(hmsClient.getDatabase(db)).isNotNull();
 
-            Path actual = catalog.databasePath(db);
+            Path actual = catalog.newDatabasePath(db);
             Path expected = new Path(this.objectStorepath + "/" + db + ".db");
             assertThat(fileIO.exists(expected)).isTrue();
             assertThat(actual).isEqualTo(expected);
@@ -256,7 +256,7 @@ public class HiveLocationTest {
 
             Identifier identifier = Identifier.create(dbName, tableName);
             String location =
-                    AbstractCatalog.dataTableLocation(warehouse, 
identifier).toUri().toString();
+                    AbstractCatalog.newTableLocation(warehouse, 
identifier).toUri().toString();
 
             String createTableSqlStr =
                     getCreateTableSqlStr(tableName, location, 
locationInProperties);

Reply via email to