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