Search in sources :

Example 31 with TableFilter

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;
}
Also used : Select(org.h2.command.dml.Select)

Example 32 with TableFilter

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);
}
Also used : IndexColumn(org.h2.table.IndexColumn)

Example 33 with TableFilter

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;
}
Also used : Table(org.h2.table.Table) Query(org.h2.command.dml.Query) ExpressionColumn(org.h2.expression.ExpressionColumn) Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) IndexColumn(org.h2.table.IndexColumn)

Example 34 with TableFilter

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;
}
Also used : TableFilter(org.h2.table.TableFilter)

Example 35 with TableFilter

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;
}
Also used : SelectUnion(org.h2.command.dml.SelectUnion) TableFilter(org.h2.table.TableFilter) ArrayList(java.util.ArrayList) Select(org.h2.command.dml.Select)

Aggregations

TableFilter (org.h2.table.TableFilter)39 IndexColumn (org.h2.table.IndexColumn)21 Column (org.h2.table.Column)20 Expression (org.h2.expression.Expression)18 ValueExpression (org.h2.expression.ValueExpression)14 ExpressionColumn (org.h2.expression.ExpressionColumn)12 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)11 Table (org.h2.table.Table)11 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)9 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)9 Select (org.h2.command.dml.Select)9 ValueString (org.h2.value.ValueString)9 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)6 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)6 CreateTable (org.h2.command.ddl.CreateTable)6 DropTable (org.h2.command.ddl.DropTable)6 Query (org.h2.command.dml.Query)6 IndexCondition (org.h2.index.IndexCondition)6 ArrayList (java.util.ArrayList)5 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)5