[Improvement](hms catalog) support show_create_database for hms catalog (#28145)
* [Improvement](hms catalog) support show_create_database for hms catalog * update
This commit is contained in:
@ -42,6 +42,7 @@ import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient;
|
||||
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
|
||||
import org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId;
|
||||
import org.apache.hadoop.hive.metastore.api.DataOperationType;
|
||||
import org.apache.hadoop.hive.metastore.api.Database;
|
||||
import org.apache.hadoop.hive.metastore.api.FieldSchema;
|
||||
import org.apache.hadoop.hive.metastore.api.LockComponent;
|
||||
import org.apache.hadoop.hive.metastore.api.LockResponse;
|
||||
@ -185,6 +186,19 @@ public class PooledHiveMetaStoreClient {
|
||||
}
|
||||
}
|
||||
|
||||
public Database getDatabase(String dbName) {
|
||||
try (CachedClient client = getClient()) {
|
||||
try {
|
||||
return client.client.getDatabase(dbName);
|
||||
} catch (Exception e) {
|
||||
client.setThrowable(e);
|
||||
throw e;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new HMSClientException("failed to get database %s from hms client", e, dbName);
|
||||
}
|
||||
}
|
||||
|
||||
public Table getTable(String dbName, String tblName) {
|
||||
try (CachedClient client = getClient()) {
|
||||
try {
|
||||
|
||||
@ -933,15 +933,28 @@ public class ShowExecutor {
|
||||
private void handleShowCreateDb() throws AnalysisException {
|
||||
ShowCreateDbStmt showStmt = (ShowCreateDbStmt) stmt;
|
||||
List<List<String>> rows = Lists.newArrayList();
|
||||
DatabaseIf db = ctx.getCurrentCatalog().getDbOrAnalysisException(showStmt.getDb());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("CREATE DATABASE `").append(ClusterNamespace.getNameFromFullName(showStmt.getDb())).append("`");
|
||||
if (db.getDbProperties().getProperties().size() > 0) {
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
sb.append(new PrintableMap<>(db.getDbProperties().getProperties(), "=", true, true, false));
|
||||
sb.append("\n)");
|
||||
CatalogIf catalog = ctx.getCurrentCatalog();
|
||||
if (catalog instanceof HMSExternalCatalog) {
|
||||
String simpleDBName = ClusterNamespace.getNameFromFullName(showStmt.getDb());
|
||||
org.apache.hadoop.hive.metastore.api.Database db = ((HMSExternalCatalog) catalog).getClient()
|
||||
.getDatabase(simpleDBName);
|
||||
sb.append("CREATE DATABASE `").append(simpleDBName).append("`")
|
||||
.append(" LOCATION '")
|
||||
.append(db.getLocationUri())
|
||||
.append("'");
|
||||
} else {
|
||||
DatabaseIf db = catalog.getDbOrAnalysisException(showStmt.getDb());
|
||||
sb.append("CREATE DATABASE `").append(ClusterNamespace.getNameFromFullName(showStmt.getDb())).append("`");
|
||||
if (db.getDbProperties().getProperties().size() > 0) {
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
sb.append(new PrintableMap<>(db.getDbProperties().getProperties(), "=", true, true, false));
|
||||
sb.append("\n)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rows.add(Lists.newArrayList(ClusterNamespace.getNameFromFullName(showStmt.getDb()), sb.toString()));
|
||||
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
|
||||
}
|
||||
|
||||
@ -1722,8 +1722,11 @@ public class HiveMetaStoreClient implements IMetaStoreClient, AutoCloseable {
|
||||
|
||||
@Override
|
||||
public Database getDatabase(String catalogName, String databaseName) throws TException {
|
||||
Database d = client.get_database(prependCatalogToDbName(catalogName, databaseName, conf));
|
||||
return deepCopy(filterHook.filterDatabase(d));
|
||||
if (hiveVersion == HiveVersion.V1_0 || hiveVersion == HiveVersion.V2_0 || hiveVersion == HiveVersion.V2_3) {
|
||||
return deepCopy(client.get_database(databaseName));
|
||||
} else {
|
||||
return deepCopy(client.get_database(prependCatalogToDbName(catalogName, databaseName, conf)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user