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;
}
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());
}
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;
}
Aggregations