qualifier = columnRef.getQualifier();
canonicalName = columnRef.getCanonicalName();
} else {
String resolvedDatabaseName = resolveDatabase(block, columnRef.getQualifier());
if (resolvedDatabaseName == null) {
throw new NoSuchColumnException(columnRef.getQualifier());
}
qualifier = CatalogUtil.buildFQName(resolvedDatabaseName, columnRef.getQualifier());
canonicalName = CatalogUtil.buildFQName(qualifier, columnRef.getName());
}
qualifiedName = CatalogUtil.buildFQName(qualifier, columnRef.getName());
RelationNode relationOp = block.getRelation(qualifier);
// if a column name is outside of this query block
if (relationOp == null) {
// TODO - nested query can only refer outer query block? or not?
for (QueryBlock eachBlock : queryBlocks.values()) {
if (eachBlock.existsRelation(qualifier)) {
relationOp = eachBlock.getRelation(qualifier);
}
}
}
// If we cannot find any relation against a qualified column name
if (relationOp == null) {
throw new NoSuchColumnException(canonicalName);
}
if (block.isAlreadyRenamedTableName(CatalogUtil.extractQualifier(canonicalName))) {
String changedName = CatalogUtil.buildFQName(
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.