diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsSemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsSemanticAnalyzer.java index 8a3ded5..5b77e6f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsSemanticAnalyzer.java @@ -522,6 +522,7 @@ public ColumnStatsSemanticAnalyzer(HiveConf conf, ASTNode tree) throws SemanticE boolean isPartitionStats = isPartitionLevelStats(tree); PartitionList partList = null; checkForPartitionColumns(colNames, getPartitionKeys(tableName)); + validateSpecifiedColumnNames(tableName, colNames); if (isPartitionStats) { isTableLevel = false; @@ -545,6 +546,25 @@ public ColumnStatsSemanticAnalyzer(HiveConf conf, ASTNode tree) throws SemanticE } } + // fail early if the columns specified for column statistics are not valid + private void validateSpecifiedColumnNames(String tableName, List specifiedCols) + throws SemanticException { + List fields = null; + try { + fields = db.getTable(tableName).getAllCols(); + } catch (HiveException e) { + throw new SemanticException(ErrorMsg.INVALID_TABLE.getMsg(tableName)); + } + List tableCols = Utilities.getColumnNamesFromFieldSchema(fields); + + for(String sc : specifiedCols) { + if (!tableCols.contains(sc.toLowerCase())) { + String msg = "'" + sc + "' (possible columns are " + tableCols.toString() + ")"; + throw new SemanticException(ErrorMsg.INVALID_COLUMN.getMsg(msg)); + } + } + } + private List getPartitionKeys(String tableName) throws SemanticException { List fields; try {