diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java index 4db9863..1931880 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java @@ -686,13 +686,34 @@ private static SelectOperator genReduceSinkAndBacktrackSelect(Operator input, int numReducers, Operation acidOperation, boolean strictMode, List keepColNames) throws SemanticException { // 1. Generate RS operator - if (input.getSchema().getTableNames().size() != 1) { + // 1.1 Prune the tableNames, only count the tableNames that are not empty strings + // as empty string in table aliases is only allowed for virtual columns. + String tableAlias = null; + Set tableNames = input.getSchema().getTableNames(); + for (String tableName : tableNames) { + if (tableName != null) { + if (tableName.length() == 0) { + if (tableAlias == null) { + tableAlias = tableName; + } + } else { + if (tableAlias == null || tableAlias.length() == 0) { + tableAlias = tableName; + } else { + if (!tableName.equals(tableAlias)) { + throw new SemanticException( + "In CBO return path, genReduceSinkAndBacktrackSelect is expecting only one tableAlias but there is more than one"); + } + } + } + } + } + if (tableAlias == null) { throw new SemanticException( - "In CBO return path, genReduceSinkAndBacktrackSelect is expecting only one SelectOp but there is " - + input.getSchema().getTableNames().size()); + "In CBO return path, genReduceSinkAndBacktrackSelect is expecting only one tableAlias but there is none"); } - ReduceSinkOperator rsOp = genReduceSink(input, input.getSchema().getTableNames().iterator() - .next(), keys, tag, partitionCols, order, numReducers, acidOperation, strictMode); + // 1.2 Now generate RS operator + ReduceSinkOperator rsOp = genReduceSink(input, tableAlias, keys, tag, partitionCols, order, numReducers, acidOperation, strictMode); // 2. Generate backtrack Select operator Map descriptors = buildBacktrackFromReduceSink(keepColNames,