use of org.h2.command.dml.SelectUnion in project ignite by apache.
the class GridSqlQueryParser method collectOptimizedTableFiltersOrder.
/**
* @param qry Query.
*/
private void collectOptimizedTableFiltersOrder(Query qry) {
if (qry instanceof SelectUnion) {
collectOptimizedTableFiltersOrder(((SelectUnion) qry).getLeft());
collectOptimizedTableFiltersOrder(((SelectUnion) qry).getRight());
} else {
Select select = (Select) qry;
TableFilter filter = select.getTopTableFilter();
int i = 0;
do {
assert0(filter != null, select);
assert0(filter.getNestedJoin() == null, select);
// Here all the table filters must have generated unique aliases,
// thus we can store them in the same map for all the subqueries.
optimizedTableFilterOrder.put(filter.getTableAlias(), i++);
Table tbl = filter.getTable();
// Go down and collect inside of optimized subqueries.
if (tbl instanceof TableView) {
ViewIndex viewIdx = (ViewIndex) filter.getIndex();
collectOptimizedTableFiltersOrder(viewIdx.getQuery());
}
filter = filter.getJoin();
} while (filter != null);
}
}
use of org.h2.command.dml.SelectUnion in project ignite by apache.
the class GridH2CollocationModel method buildCollocationModel.
/**
* @param upper Upper.
* @param filter Filter.
* @param qry Query.
* @param unions Unions.
* @param validate Query validation flag.
* @return Built model.
*/
private static GridH2CollocationModel buildCollocationModel(GridH2CollocationModel upper, int filter, Query qry, List<GridH2CollocationModel> unions, boolean validate) {
if (qry.isUnion()) {
if (unions == null)
unions = new ArrayList<>();
SelectUnion union = (SelectUnion) qry;
GridH2CollocationModel left = buildCollocationModel(upper, filter, union.getLeft(), unions, validate);
GridH2CollocationModel right = buildCollocationModel(upper, filter, union.getRight(), unions, validate);
assert left != null;
assert right != null;
return upper != null ? upper : left;
}
Select select = (Select) qry;
List<TableFilter> list = new ArrayList<>();
for (TableFilter f = select.getTopTableFilter(); f != null; f = f.getJoin()) list.add(f);
TableFilter[] filters = list.toArray(new TableFilter[list.size()]);
GridH2CollocationModel cm = createChildModel(upper, filter, unions, true, validate);
cm.childFilters(filters);
for (int i = 0; i < filters.length; i++) {
TableFilter f = filters[i];
if (f.getTable().isView())
buildCollocationModel(cm, i, getSubQuery(f), null, validate);
else if (f.getTable() instanceof GridH2Table)
createChildModel(cm, i, null, false, validate);
}
return upper != null ? upper : cm;
}
Aggregations