Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -205,23 +206,28 @@ private static String getColTypeOf(Table tbl, String partKey) {
protected static List<String> getColumnTypes(Table tbl, List<String> colNames) {
List<String> colTypes = new ArrayList<>();
List<FieldSchema> cols = tbl.getCols();
List<String> copyColNames = new ArrayList<>(colNames);

for (String colName : copyColNames) {
for (FieldSchema col : cols) {
if (colName.equalsIgnoreCase(col.getName())) {
String type = col.getType();
TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(type);
if (typeInfo.getCategory() != ObjectInspector.Category.PRIMITIVE) {
logTypeWarning(colName, type);
colNames.remove(colName);
} else {
colTypes.add(type);
}
Map<String, String> colTypeMap = new HashMap<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! When I created HIVE-29551, I had in mind do it without a HashMap if possible. There are two types of usages, depending on where the column names came from:

  • ColumnStatsSemanticAnalyzer#getColumnName
  • Utilities.getColumnNamesFromFieldSchema
    The latter iterates over a list of FieldSchema, so the type info can be obtained from these items as well.

The HashMap is only needed when the ASTNode has 3 children.


for (FieldSchema col : cols) {
colTypeMap.put(col.getName().toLowerCase(), col.getType());
}

List<String> primColNames = new ArrayList<>();
for (String colName : colNames) {
String type = colTypeMap.get(colName.toLowerCase());
if (type != null) {
TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(type);
if (typeInfo.getCategory() != ObjectInspector.Category.PRIMITIVE) {
logTypeWarning(colName, type);
} else {
primColNames.add(colName);
colTypes.add(type);
}
}
}

colNames.clear();
colNames.addAll(primColNames);
return colTypes;
}

Expand Down
Loading