Skip to content

Commit

Permalink
HIVE-28279: Output the database name for SHOW EXTENDED TABLES statement
Browse files Browse the repository at this point in the history
  • Loading branch information
wecharyu committed May 23, 2024
1 parent 019017d commit a23747c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ShowTablesDesc implements DDLDesc, Serializable {
private static final long serialVersionUID = 1L;

private static final String TABLES_VIEWS_SCHEMA = "tab_name#string";
private static final String EXTENDED_TABLES_SCHEMA = "tab_name,table_type#string,string";
private static final String EXTENDED_TABLES_SCHEMA = "db_name,tab_name,table_type#string,string,string";

private final String resFile;
private final String dbName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void showTablesExtended(DataOutputStream out, List<Table> tables) throws HiveExc
List<Map<String, Object>> tableDataList = new ArrayList<>();
for (Table table : tables) {
Map<String, Object> tableData = ImmutableMap.of(
"Database Name", table.getDbName(),
"Table Name", table.getTableName(),
"Table Type", table.getTableType().toString());
tableDataList.add(tableData);
Expand Down Expand Up @@ -104,10 +105,10 @@ void showTablesExtended(DataOutputStream out, List<Table> tables) throws HiveExc
try {
TextMetaDataTable mdt = new TextMetaDataTable();
if (!SessionState.get().isHiveServerQuery()) {
mdt.addRow("# Table Name", "Table Type");
mdt.addRow("# Database Name", "Table Name", "Table Type");
}
for (Table table : tables) {
mdt.addRow(table.getTableName(), table.getTableType().toString());
mdt.addRow(table.getDbName(), table.getTableName(), table.getTableType().toString());
}
// In case the query is served by HiveServer2, don't pad it with spaces,
// as HiveServer2 output is consumed by JDBC/ODBC clients.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PREHOOK: Input: database:default
POSTHOOK: query: SHOW EXTENDED TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
{"tables":[{"Table Name":"t","Table Type":"MANAGED_TABLE"}]}
{"tables":[{"Database Name":"default","Table Name":"t","Table Type":"MANAGED_TABLE"}]}
PREHOOK: query: SHOW TABLE EXTENDED LIKE 't'
PREHOOK: type: SHOW_TABLESTATUS
POSTHOOK: query: SHOW TABLE EXTENDED LIKE 't'
Expand Down
24 changes: 12 additions & 12 deletions ql/src/test/results/clientpositive/llap/show_tables.q.out
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ PREHOOK: Input: database:test_db
POSTHOOK: query: SHOW EXTENDED TABLES FROM test_db
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:test_db
# Table Name Table Type
bar_n0 MANAGED_TABLE
baz MANAGED_TABLE
foo_n4 MANAGED_TABLE
test_view_n100 VIRTUAL_VIEW
# Database Name Table Name Table Type
test_db bar_n0 MANAGED_TABLE
test_db baz MANAGED_TABLE
test_db foo_n4 MANAGED_TABLE
test_db test_view_n100 VIRTUAL_VIEW
PREHOOK: query: EXPLAIN SHOW TABLES IN test_db
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:test_db
Expand Down Expand Up @@ -222,11 +222,11 @@ PREHOOK: Input: database:test_db
POSTHOOK: query: SHOW EXTENDED TABLES IN test_db
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:test_db
# Table Name Table Type
bar_n0 MANAGED_TABLE
baz MANAGED_TABLE
foo_n4 MANAGED_TABLE
test_view_n100 VIRTUAL_VIEW
# Database Name Table Name Table Type
test_db bar_n0 MANAGED_TABLE
test_db baz MANAGED_TABLE
test_db foo_n4 MANAGED_TABLE
test_db test_view_n100 VIRTUAL_VIEW
PREHOOK: query: EXPLAIN SHOW TABLES IN test_db "test%"
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:test_db
Expand Down Expand Up @@ -344,8 +344,8 @@ PREHOOK: Input: database:test_db
POSTHOOK: query: SHOW EXTENDED TABLES IN test_db WHERE `table_type` = "VIRTUAL_VIEW"
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:test_db
# Table Name Table Type
test_view_n100 VIRTUAL_VIEW
# Database Name Table Name Table Type
test_db test_view_n100 VIRTUAL_VIEW
PREHOOK: query: SHOW TABLE EXTENDED IN test_db LIKE foo_n4
PREHOOK: type: SHOW_TABLESTATUS
POSTHOOK: query: SHOW TABLE EXTENDED IN test_db LIKE foo_n4
Expand Down

0 comments on commit a23747c

Please sign in to comment.