Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wecharyu committed Jun 4, 2024
1 parent fb49693 commit 12011b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.google.common.collect.ImmutableMap;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.ddl.ShowUtils;
import org.apache.hadoop.hive.ql.ddl.ShowUtils.TextMetaDataTable;
Expand All @@ -37,6 +36,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
* Formats SHOW TABLES results.
Expand All @@ -52,7 +52,7 @@ public static ShowTablesFormatter getFormatter(HiveConf conf) {

public abstract void showTables(DataOutputStream out, List<String> tables) throws HiveException;

abstract void showTablesExtended(DataOutputStream out, List<Pair<String, String>> tables) throws HiveException;
abstract void showTablesExtended(DataOutputStream out, TreeMap<String, String> tableNameToType) throws HiveException;

// ------ Implementations ------

Expand All @@ -63,16 +63,16 @@ public void showTables(DataOutputStream out, List<String> tables) throws HiveExc
}

@Override
void showTablesExtended(DataOutputStream out, List<Pair<String, String>> tables) throws HiveException {
if (tables.isEmpty()) {
void showTablesExtended(DataOutputStream out, TreeMap<String, String> tableNameToType) throws HiveException {
if (tableNameToType.isEmpty()) {
return;
}

List<Map<String, Object>> tableDataList = new ArrayList<>();
for (Pair<String, String> table : tables) {
for (Map.Entry<String, String> table : tableNameToType.entrySet()) {
Map<String, Object> tableData = ImmutableMap.of(
"Table Name", table.getLeft(),
"Table Type", table.getRight());
"Table Name", table.getKey(),
"Table Type", table.getValue());
tableDataList.add(tableData);
}

Expand All @@ -97,8 +97,8 @@ public void showTables(DataOutputStream out, List<String> tables) throws HiveExc
}

@Override
void showTablesExtended(DataOutputStream out, List<Pair<String, String>> tables) throws HiveException {
if (tables.isEmpty()) {
void showTablesExtended(DataOutputStream out, TreeMap<String, String> tableNameToType) throws HiveException {
if (tableNameToType.isEmpty()) {
return;
}

Expand All @@ -107,8 +107,8 @@ void showTablesExtended(DataOutputStream out, List<Pair<String, String>> tables)
if (!SessionState.get().isHiveServerQuery()) {
mdt.addRow("# Table Name", "Table Type");
}
for (Pair<String, String> table : tables) {
mdt.addRow(table.getLeft(), table.getRight());
for (Map.Entry<String, String> table : tableNameToType.entrySet()) {
mdt.addRow(table.getKey(), table.getValue());
}
// 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 @@ -26,9 +26,8 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.TreeMap;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
Expand Down Expand Up @@ -75,22 +74,20 @@ private void showTables() throws HiveException {
}

private void showTablesExtended() throws HiveException {
List<Pair<String, String>> tableTypePairs = new ArrayList<>();
TreeMap<String, String> tableNameToType = new TreeMap<>();
String pattern = MetaStoreUtils.convertSqlPatternToRegExp(desc.getPattern());
TableType typeFilter = desc.getTypeFilter();
TableType[] tableTypes = typeFilter == null ? TableType.values() : new TableType[]{typeFilter};
for (TableType tableType : tableTypes) {
String typeString = tableType.toString();
List<String> tables = context.getDb().getTablesByType(desc.getDbName(), pattern, tableType);
tableTypePairs.addAll(tables.stream()
.map(table -> Pair.of(table, typeString)).collect(Collectors.toList()));
tables.forEach(name -> tableNameToType.put(name, typeString));
}
Collections.sort(tableTypePairs, Comparator.comparing(Pair::getLeft));
LOG.debug("Found {} table(s) matching the SHOW EXTENDED TABLES statement.", tableTypePairs.size());
LOG.debug("Found {} table(s) matching the SHOW EXTENDED TABLES statement.", tableNameToType.size());

try (DataOutputStream os = ShowUtils.getOutputStream(new Path(desc.getResFile()), context)) {
ShowTablesFormatter formatter = ShowTablesFormatter.getFormatter(context.getConf());
formatter.showTablesExtended(os, tableTypePairs);
formatter.showTablesExtended(os, tableNameToType);
} catch (Exception e) {
throw new HiveException(e, ErrorMsg.GENERIC_ERROR, "in database " + desc.getDbName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,7 @@ public List<String> getTables(String catName, String dbName, String tablePattern
req.setTblNames(null);
req.setTablesPattern(tablePattern);
if (processorCapabilities != null)
req.setProcessorCapabilities(new ArrayList<String>(Arrays.asList(processorCapabilities)));
req.setProcessorCapabilities(Arrays.asList(processorCapabilities));
if (processorIdentifier != null)
req.setProcessorIdentifier(processorIdentifier);
req.setProjectionSpec(projectionsSpec);
Expand Down

0 comments on commit 12011b3

Please sign in to comment.