Source source,
Map<SelectorName, Table> usedSelectors ) {
if (source instanceof Selector) {
// No join required ...
assert source instanceof AllNodes || source instanceof NamedSelector;
Selector selector = (Selector)source;
PlanNode node = new PlanNode(Type.SOURCE);
if (selector.hasAlias()) {
node.addSelector(selector.alias());
node.setProperty(Property.SOURCE_ALIAS, selector.alias());
node.setProperty(Property.SOURCE_NAME, selector.name());
} else {
node.addSelector(selector.name());
node.setProperty(Property.SOURCE_NAME, selector.name());
}
// Validate the source name and set the available columns ...
NameFactory nameFactory = context.getExecutionContext().getValueFactories().getNameFactory();
// Always use the qualified form when searching for tables
Table table = context.getSchemata().getTable(selector.name().qualifiedForm(nameFactory));
if (table != null) {
if (table instanceof View) context.getHints().hasView = true;
if (usedSelectors.put(selector.aliasOrName(), table) != null) {
// There was already a table with this alias or name ...
I18n msg = GraphI18n.selectorNamesMayNotBeUsedMoreThanOnce;
context.getProblems().addError(msg, selector.aliasOrName().getString());
}
node.setProperty(Property.SOURCE_COLUMNS, table.getColumns());
} else {
context.getProblems().addError(GraphI18n.tableDoesNotExist, selector.name());
}
return node;
}
if (source instanceof Join) {
Join join = (Join)source;