use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlJoin in project ignite by apache.
the class GridSqlQueryParser method parseSelect.
/**
* @param select Select.
*/
private GridSqlSelect parseSelect(Select select) {
GridSqlSelect res = (GridSqlSelect) h2ObjToGridObj.get(select);
if (res != null)
return res;
res = new GridSqlSelect();
h2ObjToGridObj.put(select, res);
res.distinct(select.isDistinct());
Expression where = CONDITION.get(select);
res.where(parseExpression(where, true));
ArrayList<TableFilter> tableFilters = new ArrayList<>();
TableFilter filter = select.getTopTableFilter();
boolean isForUpdate = SELECT_IS_FOR_UPDATE.get(select);
do {
assert0(filter != null, select);
assert0(filter.getNestedJoin() == null, select);
// Can use optimized join order only if we are not inside of an expression.
if (parsingSubQryExpression == 0 && optimizedTableFilterOrder != null) {
String tblAlias = filter.getTableAlias();
int idx = optimizedTableFilterOrder.get(tblAlias);
setElementAt(tableFilters, idx, filter);
} else
tableFilters.add(filter);
filter = filter.getJoin();
} while (filter != null);
// Build FROM clause from correctly ordered table filters.
GridSqlElement from = null;
for (int i = 0; i < tableFilters.size(); i++) {
TableFilter f = tableFilters.get(i);
GridSqlElement gridFilter = parseTableFilter(f);
from = from == null ? gridFilter : new GridSqlJoin(from, gridFilter, f.isJoinOuter(), parseExpression(f.getJoinCondition(), true));
}
res.from(from);
if (isForUpdate) {
if (!(from instanceof GridSqlTable || (from instanceof GridSqlAlias && from.size() == 1 && from.child() instanceof GridSqlTable))) {
throw new IgniteSQLException("SELECT FOR UPDATE with joins is not supported.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
GridSqlTable gridTbl = from instanceof GridSqlTable ? (GridSqlTable) from : ((GridSqlAlias) from).child();
GridH2Table tbl = gridTbl.dataTable();
if (tbl == null) {
throw new IgniteSQLException("SELECT FOR UPDATE query must involve Ignite table.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
if (select.getLimit() != null || select.getOffset() != null) {
throw new IgniteSQLException("LIMIT/OFFSET clauses are not supported for SELECT FOR UPDATE.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
if (SELECT_IS_GROUP_QUERY.get(select)) {
throw new IgniteSQLException("SELECT FOR UPDATE with aggregates and/or GROUP BY is not supported.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
if (select.isDistinct())
throw new IgniteSQLException("DISTINCT clause is not supported for SELECT FOR UPDATE.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
if (SplitterUtils.hasSubQueries(res))
throw new IgniteSQLException("Sub queries are not supported for SELECT FOR UPDATE.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
ArrayList<Expression> expressions = select.getExpressions();
for (int i = 0; i < expressions.size(); i++) res.addColumn(parseExpression(expressions.get(i), true), i < select.getColumnCount());
int[] grpIdx = GROUP_INDEXES.get(select);
if (grpIdx != null)
res.groupColumns(grpIdx);
int havingIdx = HAVING_INDEX.get(select);
if (havingIdx >= 0)
res.havingColumn(havingIdx);
res.forUpdate(isForUpdate);
processSortOrder(select.getSortOrder(), res);
res.limit(parseExpression(select.getLimit(), false));
res.offset(parseExpression(select.getOffset(), false));
return res;
}
Aggregations