use of org.h2.table.TableFilter in project ignite by apache.
the class CollocationModel method childFilters.
/**
* @param childFilters New child filters.
* @return {@code true} If child filters were updated.
*/
private boolean childFilters(TableFilter[] childFilters) {
assert childFilters != null;
assert view;
Select select = childFilters[0].getSelect();
assert this.select == null || this.select == select;
if (this.select == null) {
this.select = select;
assert this.childFilters == null;
} else if (Arrays.equals(this.childFilters, childFilters))
return false;
if (this.childFilters == null || this.childFilters.length != childFilters.length) {
// We have to clone because H2 reuses array and reorders elements.
this.childFilters = childFilters.clone();
children = new CollocationModel[childFilters.length];
} else {
// We have to copy because H2 reuses array and reorders elements.
System.arraycopy(childFilters, 0, this.childFilters, 0, childFilters.length);
Arrays.fill(children, null);
}
// Reset results.
type = null;
multiplier = null;
return true;
}
use of org.h2.table.TableFilter in project ignite by apache.
the class GridH2IndexBase method createLookupBatch.
/**
* {@inheritDoc}
*/
@Override
public IndexLookupBatch createLookupBatch(TableFilter[] filters, int filter) {
GridH2QueryContext qctx = GridH2QueryContext.get();
if (qctx == null || qctx.distributedJoinMode() == OFF || !getTable().isPartitioned())
return null;
IndexColumn affCol = getTable().getAffinityKeyColumn();
GridH2RowDescriptor desc = getTable().rowDescriptor();
int affColId = -1;
boolean ucast = false;
if (affCol != null) {
affColId = affCol.column.getColumnId();
int[] masks = filters[filter].getMasks();
if (masks != null) {
ucast = (masks[affColId] & IndexCondition.EQUALITY) != 0 || desc.checkKeyIndexCondition(masks, IndexCondition.EQUALITY);
}
}
GridCacheContext<?, ?> cctx = getTable().rowDescriptor().context();
return new DistributedLookupBatch(cctx, ucast, affColId);
}
use of org.h2.table.TableFilter in project ignite by apache.
the class GridH2CollocationModel method isAffinityColumn.
/**
* @param f Table filter.
* @param expCol Expression column.
* @param validate Query validation flag.
* @return {@code true} It it is an affinity column.
*/
private static boolean isAffinityColumn(TableFilter f, ExpressionColumn expCol, boolean validate) {
Column col = expCol.getColumn();
if (col == null)
return false;
Table t = col.getTable();
if (t.isView()) {
Query qry;
if (f.getIndex() != null)
qry = getSubQuery(f);
else
qry = GridSqlQueryParser.VIEW_QUERY.get((TableView) t);
return isAffinityColumn(qry, expCol, validate);
}
if (t instanceof GridH2Table) {
if (validate && ((GridH2Table) t).rowDescriptor().context().customAffinityMapper())
throw customAffinityError(((GridH2Table) t).cacheName());
IndexColumn affCol = ((GridH2Table) t).getAffinityKeyColumn();
return affCol != null && col.getColumnId() == affCol.column.getColumnId();
}
return false;
}
use of org.h2.table.TableFilter in project ignite by apache.
the class GridH2CollocationModel method toString.
/**
* @param b String builder.
* @param lvl Depth level.
*/
private boolean toString(SB b, int lvl) {
boolean res = false;
if (lvl == 0) {
TableFilter f = filter();
String tblAlias = f == null ? "^" : f.getTableAlias();
b.a("[tbl=").a(tblAlias).a(", type=").a(type).a(", mul=").a(multiplier).a("]");
res = true;
} else if (childFilters != null) {
assert lvl > 0;
lvl--;
for (int i = 0; i < childFilters.length; i++) {
if (lvl == 0)
b.a(" | ");
res |= child(i, true).toString(b, lvl);
}
if (lvl == 0)
b.a(" | ");
}
return res;
}
use of org.h2.table.TableFilter 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