PlanNode accessNode ) {
super(context, columns);
this.accessNode = accessNode;
// Find the table name; should be
PlanNode source = accessNode.findAtOrBelow(Type.SOURCE);
if (source != null) {
this.sourceName = source.getProperty(Property.SOURCE_NAME, SelectorName.class);
// if (!AllNodes.ALL_NODES_NAME.equals(this.sourceName)) {
// throw new IllegalArgumentException();
// }
} else {
throw new IllegalArgumentException();
}
// Find the project ...
PlanNode project = accessNode.findAtOrBelow(Type.PROJECT);
if (project != null) {
List<Column> projectedColumns = project.getPropertyAsList(Property.PROJECT_COLUMNS, Column.class);
if (projectedColumns != null) {
this.projectedColumns = projectedColumns;
} else {
// Get the columns from the source columns ...
List<Schemata.Column> schemataColumns = source.getPropertyAsList(Property.SOURCE_COLUMNS, Schemata.Column.class);
this.projectedColumns = new ArrayList<Column>(schemataColumns.size());
for (Schemata.Column schemataColumn : schemataColumns) {
String columnName = schemataColumn.getName();
// PropertyType type = schemataColumn.getPropertyType();
String propertyName = columnName;
Column column = new Column(sourceName, propertyName, columnName);
this.projectedColumns.add(column);
}
}
} else {
throw new IllegalArgumentException();
}
// Add the criteria ...
List<Constraint> andedConstraints = null;
for (PlanNode select : accessNode.findAllAtOrBelow(Type.SELECT)) {
Constraint selectConstraint = select.getProperty(Property.SELECT_CRITERIA, Constraint.class);
if (andedConstraints == null) andedConstraints = new ArrayList<Constraint>();
andedConstraints.add(selectConstraint);
}
this.andedConstraints = andedConstraints != null ? andedConstraints : Collections.<Constraint>emptyList();
// Find the limit ...
Limit limit = Limit.NONE;
PlanNode limitNode = accessNode.findAtOrBelow(Type.LIMIT);
if (limitNode != null) {
Integer count = limitNode.getProperty(Property.LIMIT_COUNT, Integer.class);
if (count != null) limit = limit.withRowLimit(count.intValue());
Integer offset = limitNode.getProperty(Property.LIMIT_OFFSET, Integer.class);
if (offset != null) limit = limit.withOffset(offset.intValue());
}
this.limit = limit;
}