Index: ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java (revision 1620376) +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java (working copy) @@ -135,9 +135,7 @@ } hiveAST.select = b.node(); } else { - //TODO: We should never be here. But we will be for select null from t1. - // Once you figure out why, uncomment following line: - // throw new IllegalStateException("why am I here?"); + throw new IllegalStateException("Expected non-zero children for select."); } Index: ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/rules/HiveRelFieldTrimmer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/rules/HiveRelFieldTrimmer.java (revision 1620376) +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/rules/HiveRelFieldTrimmer.java (working copy) @@ -438,7 +438,7 @@ /** * Variant of {@link #trimFields(RelNode, BitSet, Set)} for {@link JoinRel}. - * + * * Have to do this because of the way ReflectUtil works. - if there is an * exact match, things are fine. - otherwise it doesn't allow any ambiguity(in * this case between a superClass(JoinRelBase) and an interface(HiveRel). @@ -578,14 +578,14 @@ public TrimResult trimFields(HiveJoinRel join, BitSet fieldsUsed, Set extraFields) { - return _trimFields((JoinRelBase) join, fieldsUsed, extraFields); + return _trimFields(join, fieldsUsed, extraFields); } - + public TrimResult trimFields(SemiJoinRel join, BitSet fieldsUsed, Set extraFields) { - return _trimFields((JoinRelBase) join, fieldsUsed, extraFields); + return _trimFields(join, fieldsUsed, extraFields); } - + /** * Variant of {@link #trimFields(RelNode, BitSet, Set)} for {@link SetOpRel} * (including UNION and UNION ALL). @@ -879,7 +879,7 @@ public TrimResult trimFields(final HiveTableScanRel tableAccessRel, BitSet fieldsUsed, Set extraFields) { final int fieldCount = tableAccessRel.getRowType().getFieldCount(); - if (fieldsUsed.equals(BitSets.range(fieldCount)) && extraFields.isEmpty()) { + if (fieldsUsed.isEmpty() || (fieldsUsed.equals(BitSets.range(fieldCount)) && extraFields.isEmpty())) { return trimFields((HiveRel) tableAccessRel, fieldsUsed, extraFields); } final RelNode _newTableAccessRel = tableAccessRel.project(fieldsUsed,