diff --git a/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/HiveMetaData.java b/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/HiveMetaData.java index 0579d4876..682d27ca6 100644 --- a/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/HiveMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/HiveMetaData.java @@ -48,7 +48,9 @@ public List schemas(Connection connection, String databaseName) { @Override public String tableDDL(Connection connection, @NotEmpty String databaseName, String schemaName, @NotEmpty String tableName) { - String sql = "SHOW CREATE TABLE " + format(databaseName) + "." + // In Hive, schema and database are the same concept. Fall back to schemaName when databaseName is absent. + String effectiveDb = StringUtils.isNotBlank(databaseName) ? databaseName : schemaName; + String sql = "SHOW CREATE TABLE " + format(effectiveDb) + "." + format(tableName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { StringBuilder sb = new StringBuilder(); @@ -97,7 +99,9 @@ public SqlBuilder getSqlBuilder() { // TODO 待完善 @Override public List columns(Connection connection, String databaseName, String schemaName, String tableName) { - String sql = String.format(SELECT_TAB_COLS, databaseName, tableName); + // In Hive, schema and database are the same concept. Fall back to schemaName when databaseName is absent. + String effectiveDb = StringUtils.isNotBlank(databaseName) ? databaseName : schemaName; + String sql = String.format(SELECT_TAB_COLS, effectiveDb, tableName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { List tableColumns = new ArrayList<>(); Map detailTableInfo = new HashMap<>(); @@ -268,7 +272,9 @@ public static String format(String name) { @Override public Table view(Connection connection, String databaseName, String schemaName, String viewName) { - String sql = String.format(VIEW_SQL, databaseName, viewName); + // In Hive, schema and database are the same concept. Fall back to schemaName when databaseName is absent. + String effectiveDb = StringUtils.isNotBlank(databaseName) ? databaseName : schemaName; + String sql = String.format(VIEW_SQL, effectiveDb, viewName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { Table table = new Table(); table.setDatabaseName(databaseName);