Search in sources :

Example 1 with CacheQueryPartitionInfo

use of org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo in project ignite by apache.

the class GridSqlQuerySplitter method mergePartitionInfo.

/**
     * Merges two partition info arrays, removing duplicates
     *
     * @param a Partition info array.
     * @param b Partition info array.
     * @return Result.
     */
private static CacheQueryPartitionInfo[] mergePartitionInfo(CacheQueryPartitionInfo[] a, CacheQueryPartitionInfo[] b) {
    assert a != null;
    assert b != null;
    if (a.length == 1 && b.length == 1) {
        if (a[0].equals(b[0]))
            return new CacheQueryPartitionInfo[] { a[0] };
        return new CacheQueryPartitionInfo[] { a[0], b[0] };
    }
    ArrayList<CacheQueryPartitionInfo> list = new ArrayList<>(a.length + b.length);
    for (CacheQueryPartitionInfo part : a) list.add(part);
    for (CacheQueryPartitionInfo part : b) {
        int i = 0;
        while (i < list.size() && !list.get(i).equals(part)) i++;
        if (i == list.size())
            list.add(part);
    }
    CacheQueryPartitionInfo[] result = new CacheQueryPartitionInfo[list.size()];
    for (int i = 0; i < list.size(); i++) result[i] = list.get(i);
    return result;
}
Also used : CacheQueryPartitionInfo(org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo) ArrayList(java.util.ArrayList)

Example 2 with CacheQueryPartitionInfo

use of org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo in project ignite by apache.

the class GridSqlQuerySplitter method extractPartitionFromEquality.

/**
     * Analyses the equality operation and extracts the partition if possible
     *
     * @param op AST equality operation.
     * @param ctx Kernal Context.
     * @return partition info, or {@code null} if none identified
     */
private static CacheQueryPartitionInfo extractPartitionFromEquality(GridSqlOperation op, GridKernalContext ctx) throws IgniteCheckedException {
    assert op.operationType() == GridSqlOperationType.EQUAL;
    GridSqlElement left = op.child(0);
    GridSqlElement right = op.child(1);
    if (!(left instanceof GridSqlColumn))
        return null;
    if (!(right instanceof GridSqlConst) && !(right instanceof GridSqlParameter))
        return null;
    GridSqlColumn column = (GridSqlColumn) left;
    assert column.column().getTable() instanceof GridH2Table;
    GridH2Table tbl = (GridH2Table) column.column().getTable();
    GridH2RowDescriptor desc = tbl.rowDescriptor();
    IndexColumn affKeyCol = tbl.getAffinityKeyColumn();
    int colId = column.column().getColumnId();
    if ((affKeyCol == null || colId != affKeyCol.column.getColumnId()) && !desc.isKeyColumn(colId))
        return null;
    if (right instanceof GridSqlConst) {
        GridSqlConst constant = (GridSqlConst) right;
        return new CacheQueryPartitionInfo(ctx.affinity().partition(tbl.cacheName(), constant.value().getObject()), null, -1);
    }
    assert right instanceof GridSqlParameter;
    GridSqlParameter param = (GridSqlParameter) right;
    return new CacheQueryPartitionInfo(-1, tbl.cacheName(), param.index());
}
Also used : GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) CacheQueryPartitionInfo(org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo) IndexColumn(org.h2.table.IndexColumn)

Example 3 with CacheQueryPartitionInfo

use of org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo in project ignite by apache.

the class IgniteH2Indexing method calculateQueryPartitions.

/**
     * Bind query parameters and calculate partitions derived from the query.
     *
     * @return Partitions.
     */
private int[] calculateQueryPartitions(CacheQueryPartitionInfo[] partInfoList, Object[] params) throws IgniteCheckedException {
    ArrayList<Integer> list = new ArrayList<>(partInfoList.length);
    for (CacheQueryPartitionInfo partInfo : partInfoList) {
        int partId = partInfo.partition() < 0 ? kernalContext().affinity().partition(partInfo.cacheName(), params[partInfo.paramIdx()]) : partInfo.partition();
        int i = 0;
        while (i < list.size() && list.get(i) < partId) i++;
        if (i < list.size()) {
            if (list.get(i) > partId)
                list.add(i, partId);
        } else
            list.add(partId);
    }
    int[] result = new int[list.size()];
    for (int i = 0; i < list.size(); i++) result[i] = list.get(i);
    return result;
}
Also used : IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) ArrayList(java.util.ArrayList) CacheQueryPartitionInfo(org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo)

Aggregations

CacheQueryPartitionInfo (org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo)3 ArrayList (java.util.ArrayList)2 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)1 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)1 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)1 IndexColumn (org.h2.table.IndexColumn)1