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/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 9b281bc88f [hive] HiveCatalog.listViews method reduces the number of
queries for hms metadata. (#4501)
9b281bc88f is described below
commit 9b281bc88f12d413f0c4cc4453e664060c55413d
Author: Kerwin <[email protected]>
AuthorDate: Tue Nov 12 13:24:30 2024 +0800
[hive] HiveCatalog.listViews method reduces the number of queries for hms
metadata. (#4501)
---
.../java/org/apache/paimon/hive/HiveCatalog.java | 66 +++++++++-------------
.../org/apache/paimon/hive/HiveTableUtils.java | 4 +-
2 files changed, 29 insertions(+), 41 deletions(-)
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 51c800e568..2bf16c0f44 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
@@ -530,25 +530,13 @@ public class HiveCatalog extends AbstractCatalog {
getDatabase(databaseName);
try {
- List<String> tables = clients.run(client ->
client.getAllTables(databaseName));
- List<String> views = new ArrayList<>();
- for (String tableName : tables) {
- Table table;
- try {
- table = getHmsTable(Identifier.create(databaseName,
tableName));
- } catch (TableNotExistException e) {
- continue;
- }
- if (isView(table)) {
- views.add(tableName);
- }
- }
- return views;
+ return clients.run(
+ client -> client.getTables(databaseName, "*",
TableType.VIRTUAL_VIEW));
} catch (TException e) {
- throw new RuntimeException("Failed to list all tables in database
" + databaseName, e);
+ throw new RuntimeException("Failed to list views in database " +
databaseName, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- throw new RuntimeException("Interrupted in call to listTables " +
databaseName, e);
+ throw new RuntimeException("Interrupted in call to getTables " +
databaseName, e);
}
}
@@ -570,20 +558,7 @@ public class HiveCatalog extends AbstractCatalog {
} catch (ViewNotExistException ignored) {
}
- try {
- String fromDB = fromView.getDatabaseName();
- String fromViewName = fromView.getTableName();
- Table table = clients.run(client -> client.getTable(fromDB,
fromViewName));
- table.setDbName(toView.getDatabaseName());
- table.setTableName(toView.getTableName());
- clients.execute(client -> client.alter_table(fromDB, fromViewName,
table));
- } catch (TException e) {
- throw new RuntimeException("Failed to rename view " +
fromView.getFullName(), e);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new RuntimeException(
- "Interrupted in call to rename view " +
fromView.getFullName(), e);
- }
+ renameHiveTable(fromView, toView);
}
@Override
@@ -779,12 +754,7 @@ public class HiveCatalog extends AbstractCatalog {
@Override
protected void renameTableImpl(Identifier fromTable, Identifier toTable) {
try {
- String fromDB = fromTable.getDatabaseName();
- String fromTableName = fromTable.getTableName();
- Table table = clients.run(client -> client.getTable(fromDB,
fromTableName));
- table.setDbName(toTable.getDatabaseName());
- table.setTableName(toTable.getTableName());
- clients.execute(client -> client.alter_table(fromDB,
fromTableName, table));
+ Table table = renameHiveTable(fromTable, toTable);
Path fromPath = getTableLocation(fromTable);
if (!new SchemaManager(fileIO, fromPath).listAllIds().isEmpty()) {
@@ -816,6 +786,24 @@ public class HiveCatalog extends AbstractCatalog {
}
}
+ private Table renameHiveTable(Identifier fromTable, Identifier toTable) {
+ try {
+ String fromDB = fromTable.getDatabaseName();
+ String fromTableName = fromTable.getTableName();
+ Table table = clients.run(client -> client.getTable(fromDB,
fromTableName));
+ table.setDbName(toTable.getDatabaseName());
+ table.setTableName(toTable.getTableName());
+ clients.execute(client -> client.alter_table(fromDB,
fromTableName, table));
+
+ return table;
+ } catch (TException e) {
+ throw new RuntimeException("Failed to rename table " +
fromTable.getFullName(), e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException("Interrupted in call to renameTable",
e);
+ }
+ }
+
@Override
protected void alterTableImpl(Identifier identifier, List<SchemaChange>
changes)
throws TableNotExistException, ColumnAlreadyExistException,
ColumnNotExistException {
@@ -865,7 +853,7 @@ public class HiveCatalog extends AbstractCatalog {
@Override
public void repairCatalog() {
- List<String> databases = null;
+ List<String> databases;
try {
databases = listDatabasesInFileSystem(new Path(warehouse));
} catch (IOException e) {
@@ -1002,8 +990,8 @@ public class HiveCatalog extends AbstractCatalog {
}
}
- private static boolean isView(Table table) {
- return TableType.valueOf(table.getTableType()) ==
TableType.VIRTUAL_VIEW;
+ public static boolean isView(Table table) {
+ return table != null &&
TableType.VIRTUAL_VIEW.name().equals(table.getTableType());
}
private Table newHmsTable(
diff --git
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveTableUtils.java
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveTableUtils.java
index fef2d39529..5e5af75e52 100644
---
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveTableUtils.java
+++
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveTableUtils.java
@@ -25,7 +25,6 @@ import org.apache.paimon.types.DataType;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.Pair;
-import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.Table;
@@ -38,12 +37,13 @@ import java.util.Map;
import static org.apache.hadoop.hive.serde.serdeConstants.FIELD_DELIM;
import static org.apache.paimon.catalog.Catalog.COMMENT_PROP;
+import static org.apache.paimon.hive.HiveCatalog.isView;
import static org.apache.paimon.table.FormatTableOptions.FIELD_DELIMITER;
class HiveTableUtils {
public static FormatTable convertToFormatTable(Table hiveTable) {
- if (TableType.valueOf(hiveTable.getTableType()) ==
TableType.VIRTUAL_VIEW) {
+ if (isView(hiveTable)) {
throw new UnsupportedOperationException("Hive view is not
supported.");
}