throws StandardException {
Joinable result;
if (fromTable instanceof FromBaseTable) {
TableBinding tb = (TableBinding)fromTable.getUserData();
if (tb == null)
throw new UnsupportedSQLException("FROM table",
fromTable);
Table aisTable = (Table)tb.getTable();
TableNode table = getTableNode(aisTable);
String name = fromTable.getCorrelationName();
if (name == null) {
if (aisTable.getName().getSchemaName().equals(rulesContext.getDefaultSchemaName()))
name = aisTable.getName().getTableName();
else
name = aisTable.getName().toString();
}
result = new TableSource(table, required, name);
}
else if (fromTable instanceof com.foundationdb.sql.parser.JoinNode) {
com.foundationdb.sql.parser.JoinNode joinNode =
(com.foundationdb.sql.parser.JoinNode)fromTable;
JoinType joinType;
switch (joinNode.getNodeType()) {
case NodeTypes.JOIN_NODE:
joinType = JoinType.INNER;
break;
case NodeTypes.HALF_OUTER_JOIN_NODE:
if (((HalfOuterJoinNode)joinNode).isRightOuterJoin())
joinType = JoinType.RIGHT;
else
joinType = JoinType.LEFT;
break;
default:
throw new UnsupportedSQLException("Unsupported join type", joinNode);
}
JoinNode join = joinNodes(toJoinNode((FromTable)joinNode.getLeftResultSet(),
required && (joinType != JoinType.RIGHT)),
toJoinNode((FromTable)joinNode.getRightResultSet(),
required && (joinType != JoinType.LEFT)),
joinType);
join.setJoinConditions(toConditions(joinNode.getJoinClause()));
result = join;
}
else if (fromTable instanceof FromSubquery) {
FromSubquery fromSubquery = (FromSubquery)fromTable;
PlanNode subquery = toQueryForSelect(fromSubquery.getSubquery(),
fromSubquery.getOrderByList(),
fromSubquery.getOffset(),
fromSubquery.getFetchFirst(),
false);
result = new SubquerySource(new Subquery(subquery, peekEquivalenceFinder()),
fromSubquery.getExposedName());
}
else
throw new UnsupportedSQLException("Unsupported FROM non-table", fromTable);
joinNodes.put(fromTable, result);
return result;
}