relationOp.getCanonicalName(),
CatalogUtil.extractSimpleName(canonicalName));
canonicalName = changedName;
}
Schema schema = relationOp.getTableSchema();
Column column = schema.getColumn(canonicalName);
if (column == null) {
throw new NoSuchColumnException(canonicalName);
}
// If code reach here, a column is found.
// But, it may be aliased from bottom logical node.
// If the column is aliased, the found name may not be used in upper node.
// Here, we try to check if column reference is already aliased.
// If so, it replaces the name with aliased name.
LogicalNode currentNode = block.getCurrentNode();
// The condition (currentNode.getInSchema().contains(column)) means
// the column can be used at the current node. So, we don't need to find aliase name.
Schema currentNodeSchema = null;
if (currentNode != null) {
if (currentNode instanceof RelationNode) {
currentNodeSchema = ((RelationNode) currentNode).getTableSchema();
} else {
currentNodeSchema = currentNode.getInSchema();
}
}
if (currentNode != null && !currentNodeSchema.contains(column)
&& currentNode.getType() != NodeType.TABLE_SUBQUERY) {
List<Column> candidates = TUtil.newList();
if (block.namedExprsMgr.isAliased(qualifiedName)) {
String alias = block.namedExprsMgr.getAlias(canonicalName);
Column found = resolveColumn(block, new ColumnReferenceExpr(alias));