use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.
the class IgniteH2Indexing method dynamicIndexCreate.
/** {@inheritDoc} */
@Override
public void dynamicIndexCreate(final String schemaName, final String tblName, final QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor) throws IgniteCheckedException {
// Locate table.
H2Schema schema = schemas.get(schemaName);
H2TableDescriptor desc = (schema != null ? schema.tableByName(tblName) : null);
if (desc == null)
throw new IgniteCheckedException("Table not found in internal H2 database [schemaName=" + schemaName + ", tblName=" + tblName + ']');
GridH2Table h2Tbl = desc.table();
// Create index.
final GridH2IndexBase h2Idx = desc.createUserIndex(idxDesc);
h2Tbl.proposeUserIndex(h2Idx);
try {
// Populate index with existing cache data.
final GridH2RowDescriptor rowDesc = h2Tbl.rowDescriptor();
SchemaIndexCacheVisitorClosure clo = new SchemaIndexCacheVisitorClosure() {
@Override
public void apply(KeyCacheObject key, int part, CacheObject val, GridCacheVersion ver, long expTime, long link) throws IgniteCheckedException {
if (expTime == 0L)
expTime = Long.MAX_VALUE;
GridH2Row row = rowDesc.createRow(key, part, val, ver, expTime);
row.link(link);
h2Idx.put(row);
}
};
cacheVisitor.visit(clo);
// At this point index is in consistent state, promote it through H2 SQL statement, so that cached
// prepared statements are re-built.
String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists);
executeSql(schemaName, sql);
} catch (Exception e) {
// Rollback and re-throw.
h2Tbl.rollbackUserIndex(h2Idx.getName());
throw e;
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.
the class IgniteH2Indexing method createSortedIndex.
/**
* Create sorted index.
*
* @param schema Schema.
* @param name Index name,
* @param tbl Table.
* @param pk Primary key flag.
* @param cols Columns.
* @return Index.
*/
public GridH2IndexBase createSortedIndex(H2Schema schema, String name, GridH2Table tbl, boolean pk, List<IndexColumn> cols, int inlineSize) {
try {
GridCacheContext cctx = tbl.cache();
if (log.isDebugEnabled())
log.debug("Creating cache index [cacheId=" + cctx.cacheId() + ", idxName=" + name + ']');
final int segments = tbl.rowDescriptor().context().config().getQueryParallelism();
return new H2TreeIndex(cctx, tbl, name, pk, cols, inlineSize, segments);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.
the class IgniteH2Indexing method addInitialUserIndex.
/**
* Add initial user index.
*
* @param schemaName Schema name.
* @param desc Table descriptor.
* @param h2Idx User index.
* @throws IgniteCheckedException If failed.
*/
private void addInitialUserIndex(String schemaName, H2TableDescriptor desc, GridH2IndexBase h2Idx) throws IgniteCheckedException {
GridH2Table h2Tbl = desc.table();
h2Tbl.proposeUserIndex(h2Idx);
try {
String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
executeSql(schemaName, sql);
} catch (Exception e) {
// Rollback and re-throw.
h2Tbl.rollbackUserIndex(h2Idx.getName());
throw e;
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table 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.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.
the class DmlAstUtils method isEqualityCondition.
/**
* @param op Operation.
* @param key true - check for key equality condition,
* otherwise check for value equality condition
* @return Whether this condition is of form {@code colName} = ?
*/
private static boolean isEqualityCondition(GridSqlOperation op, boolean key) {
if (op.operationType() != GridSqlOperationType.EQUAL)
return false;
GridSqlElement left = op.child(0);
GridSqlElement right = op.child(1);
if (!(left instanceof GridSqlColumn))
return false;
GridSqlColumn column = (GridSqlColumn) left;
if (!(column.column().getTable() instanceof GridH2Table))
return false;
GridH2RowDescriptor desc = ((GridH2Table) column.column().getTable()).rowDescriptor();
return (key ? desc.isKeyColumn(column.column().getColumnId()) : desc.isValueColumn(column.column().getColumnId())) && (right instanceof GridSqlConst || right instanceof GridSqlParameter);
}
Aggregations