throw new NoSuchColumnException(columnRef.getCanonicalName());
}
Schema schema = relationOp.getTableSchema();
Column column = schema.getColumnByFQN(columnRef.getCanonicalName());
if (column == null) {
throw new VerifyException("ERROR: no such a column '"+ columnRef.getCanonicalName() + "'");
}
return column;
} else { // if a column reference is not qualified
// if current logical node is available
if (currentNode != null && currentNode.getOutSchema() != null) {
Column found = currentNode.getOutSchema().getColumnByName(columnRef.getName());
if (found != null) {
return found;
}
}
if (block.getLatestNode() != null) {
Column found = block.getLatestNode().getOutSchema().getColumnByName(columnRef.getName());
if (found != null) {
return found;
}
}
// Trying to find columns from other relations in the current block
List<Column> candidates = TUtil.newList();
for (RelationNode rel : block.getRelations()) {
Column found = rel.getOutSchema().getColumnByName(columnRef.getName());
if (found != null) {
candidates.add(found);
}
}
if (!candidates.isEmpty()) {
return ensureUniqueColumn(candidates);
}
// Trying to find columns from other relations in other blocks
for (QueryBlock eachBlock : queryBlocks.values()) {
for (RelationNode rel : eachBlock.getRelations()) {
Column found = rel.getOutSchema().getColumnByName(columnRef.getName());
if (found != null) {
candidates.add(found);
}
}
}