private static RelNode renameTopLevelSelectInResultSchema(final RelNode rootRel,
Pair<RelNode, RelNode> topSelparentPair, List<FieldSchema> resultSchema)
throws OptiqSemanticException {
RelNode parentOforiginalProjRel = topSelparentPair.getKey();
HiveProjectRel originalProjRel = (HiveProjectRel) topSelparentPair.getValue();
// Assumption: top portion of tree could only be
// (limit)?(OB)?(ProjectRelBase)....
List<RexNode> rootChildExps = originalProjRel.getChildExps();
if (resultSchema.size() != rootChildExps.size()) {
// Safeguard against potential issues in CBO RowResolver construction. Disable CBO for now.
LOG.error(generateInvalidSchemaMessage(originalProjRel, resultSchema, 0));
throw new OptiqSemanticException("Result Schema didn't match Optimized Op Tree Schema");
}
List<String> newSelAliases = new ArrayList<String>();
String colAlias;
for (int i = 0; i < rootChildExps.size(); i++) {
colAlias = resultSchema.get(i).getName();
if (colAlias.startsWith("_")) {
colAlias = colAlias.substring(1);
}
newSelAliases.add(colAlias);
}
HiveProjectRel replacementProjectRel = HiveProjectRel.create(originalProjRel.getChild(),
originalProjRel.getChildExps(), newSelAliases);
if (rootRel == originalProjRel) {
return replacementProjectRel;
} else {