in tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java [352:405]
public static void verifyProjectedFields(QueryBlock block, Projectable projectable) throws PlanningException {
if (projectable instanceof ProjectionNode && block.hasNode(NodeType.GROUP_BY)) {
for (Target target : projectable.getTargets()) {
Set<Column> columns = EvalTreeUtil.findUniqueColumns(target.getEvalTree());
for (Column c : columns) {
if (!projectable.getInSchema().contains(c)) {
throw new PlanningException(c.getQualifiedName()
+ " must appear in the GROUP BY clause or be used in an aggregate function at node ("
+ projectable.getPID() + ")" );
}
}
}
} else if (projectable instanceof GroupbyNode) {
GroupbyNode groupbyNode = (GroupbyNode) projectable;
for (Column c : groupbyNode.getGroupingColumns()) {
if (!projectable.getInSchema().contains(c)) {
throw new PlanningException(String.format("Cannot get the field \"%s\" at node (%d)",
c, projectable.getPID()));
}
}
if (groupbyNode.hasAggFunctions()) {
for (AggregationFunctionCallEval f : groupbyNode.getAggFunctions()) {
Set<Column> columns = EvalTreeUtil.findUniqueColumns(f);
for (Column c : columns) {
if (!projectable.getInSchema().contains(c)) {
throw new PlanningException(String.format("Cannot get the field \"%s\" at node (%d)",
c, projectable.getPID()));
}
}
}
}
} else if (projectable instanceof RelationNode) {
RelationNode relationNode = (RelationNode) projectable;
for (Target target : projectable.getTargets()) {
Set<Column> columns = EvalTreeUtil.findUniqueColumns(target.getEvalTree());
for (Column c : columns) {
if (!relationNode.getTableSchema().contains(c)) {
throw new PlanningException(String.format("Cannot get the field \"%s\" at node (%d)",
c, projectable.getPID()));
}
}
}
} else {
for (Target target : projectable.getTargets()) {
Set<Column> columns = EvalTreeUtil.findUniqueColumns(target.getEvalTree());
for (Column c : columns) {
if (!projectable.getInSchema().contains(c)) {
throw new PlanningException(String.format("Cannot get the field \"%s\" at node (%d)",
c, projectable.getPID()));
}
}
}
}
}