Search in sources :

Example 36 with IndexColumn

use of org.h2.table.IndexColumn in project ignite by apache.

the class GridSqlSortColumn method toIndexColumns.

/**
 * @param tbl Table.
 * @param sortCols Sort columns.
 * @return Index columns.
 */
public static IndexColumn[] toIndexColumns(Table tbl, List<GridSqlSortColumn> sortCols) {
    assert !F.isEmpty(sortCols);
    IndexColumn[] res = new IndexColumn[sortCols.size()];
    for (int i = 0; i < res.length; i++) {
        GridSqlSortColumn sc = sortCols.get(i);
        Column col = tbl.getColumn(sc.column());
        IndexColumn c = new IndexColumn();
        c.column = col;
        c.columnName = col.getName();
        c.sortType = sc.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING;
        if (sc.nullsFirst)
            c.sortType |= SortOrder.NULLS_FIRST;
        if (sc.nullsLast)
            c.sortType |= SortOrder.NULLS_LAST;
        res[i] = c;
    }
    return res;
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) IndexColumn(org.h2.table.IndexColumn)

Example 37 with IndexColumn

use of org.h2.table.IndexColumn in project ignite by apache.

the class H2Utils method createSpatialIndex.

/**
 * Create spatial index.
 *
 * @param tbl Table.
 * @param idxName Index name.
 * @param cols Columns.
 */
public static GridH2IndexBase createSpatialIndex(GridH2Table tbl, String idxName, IndexColumn[] cols) {
    try {
        Class<?> cls = Class.forName(SPATIAL_IDX_CLS);
        Constructor<?> ctor = cls.getConstructor(GridH2Table.class, String.class, Integer.TYPE, IndexColumn[].class);
        if (!ctor.isAccessible())
            ctor.setAccessible(true);
        final int segments = tbl.rowDescriptor().context().config().getQueryParallelism();
        return (GridH2IndexBase) ctor.newInstance(tbl, idxName, segments, cols);
    } catch (Exception e) {
        throw new IgniteException("Failed to instantiate: " + SPATIAL_IDX_CLS, e);
    }
}
Also used : GridH2IndexBase(org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase) IgniteException(org.apache.ignite.IgniteException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) IndexColumn(org.h2.table.IndexColumn)

Example 38 with IndexColumn

use of org.h2.table.IndexColumn 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 39 with IndexColumn

use of org.h2.table.IndexColumn in project ignite by apache.

the class H2TableDescriptor method createUserIndex.

/**
 * Create user index.
 *
 * @param idxDesc Index descriptor.
 * @return Index.
 */
public GridH2IndexBase createUserIndex(GridQueryIndexDescriptor idxDesc) {
    IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
    IndexColumn affCol = tbl.getAffinityKeyColumn();
    List<IndexColumn> cols = new ArrayList<>(idxDesc.fields().size() + 2);
    for (String field : idxDesc.fields()) {
        Column col = tbl.getColumn(field);
        cols.add(tbl.indexColumn(col.getColumnId(), idxDesc.descending(field) ? SortOrder.DESCENDING : SortOrder.ASCENDING));
    }
    GridH2RowDescriptor desc = tbl.rowDescriptor();
    if (idxDesc.type() == QueryIndexType.SORTED) {
        cols = H2Utils.treeIndexColumns(desc, cols, keyCol, affCol);
        return idx.createSortedIndex(idxDesc.name(), tbl, false, cols, idxDesc.inlineSize());
    } else if (idxDesc.type() == QueryIndexType.GEOSPATIAL)
        return H2Utils.createSpatialIndex(tbl, idxDesc.name(), cols.toArray(new IndexColumn[cols.size()]));
    throw new IllegalStateException("Index type: " + idxDesc.type());
}
Also used : GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) ArrayList(java.util.ArrayList) IndexColumn(org.h2.table.IndexColumn)

Example 40 with IndexColumn

use of org.h2.table.IndexColumn 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)

Aggregations

IndexColumn (org.h2.table.IndexColumn)53 Column (org.h2.table.Column)23 ArrayList (java.util.ArrayList)14 Index (org.h2.index.Index)12 Value (org.h2.value.Value)12 IndexType (org.h2.index.IndexType)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 Constraint (org.h2.constraint.Constraint)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 LinkedHashMap (java.util.LinkedHashMap)5 CacheException (javax.cache.CacheException)5 TableFilter (org.h2.table.TableFilter)5 StatementBuilder (org.h2.util.StatementBuilder)5 ValueString (org.h2.value.ValueString)5 HashMap (java.util.HashMap)4 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)4 H2TreeIndexBase (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase)4 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)4 Row (org.h2.result.Row)4 ResultSet (java.sql.ResultSet)3