use of org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor in project ignite by apache.
the class DmlAstUtils method getFastUpdateArgs.
/**
* @param update UPDATE statement.
* @return {@code null} if given statement directly updates {@code _val} column with a literal or param value
* and filters by single non expression key (and, optionally, by single non expression value).
*/
public static FastUpdateArguments getFastUpdateArgs(GridSqlUpdate update) {
IgnitePair<GridSqlElement> filter = findKeyValueEqualityCondition(update.where());
if (filter == null)
return null;
if (update.cols().size() != 1)
return null;
Table tbl = update.cols().get(0).column().getTable();
if (!(tbl instanceof GridH2Table))
return null;
GridH2RowDescriptor desc = ((GridH2Table) tbl).rowDescriptor();
if (!desc.isValueColumn(update.cols().get(0).column().getColumnId()))
return null;
GridSqlElement set = update.set().get(update.cols().get(0).columnName());
if (!(set instanceof GridSqlConst || set instanceof GridSqlParameter))
return null;
return new FastUpdateArguments(operandForElement(filter.getKey()), operandForElement(filter.getValue()), operandForElement(set));
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor 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, null, -1, -1);
}
GridSqlParameter param = (GridSqlParameter) right;
return new CacheQueryPartitionInfo(-1, tbl.cacheName(), tbl.getName(), column.column().getType(), param.index());
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor in project ignite by apache.
the class IgniteH2Indexing method createTable.
/**
* Create db table by using given table descriptor.
*
* @param schemaName Schema name.
* @param schema Schema.
* @param tbl Table descriptor.
* @param conn Connection.
* @throws SQLException If failed to create db table.
* @throws IgniteCheckedException If failed.
*/
private void createTable(String schemaName, H2Schema schema, H2TableDescriptor tbl, Connection conn) throws SQLException, IgniteCheckedException {
assert schema != null;
assert tbl != null;
String keyType = dbTypeFromClass(tbl.type().keyClass());
String valTypeStr = dbTypeFromClass(tbl.type().valueClass());
SB sql = new SB();
String keyValVisibility = tbl.type().fields().isEmpty() ? " VISIBLE" : " INVISIBLE";
sql.a("CREATE TABLE ").a(tbl.fullTableName()).a(" (").a(KEY_FIELD_NAME).a(' ').a(keyType).a(keyValVisibility).a(" NOT NULL");
sql.a(',').a(VAL_FIELD_NAME).a(' ').a(valTypeStr).a(keyValVisibility);
sql.a(',').a(VER_FIELD_NAME).a(" OTHER INVISIBLE");
for (Map.Entry<String, Class<?>> e : tbl.type().fields().entrySet()) sql.a(',').a(H2Utils.withQuotes(e.getKey())).a(' ').a(dbTypeFromClass(e.getValue())).a(tbl.type().property(e.getKey()).notNull() ? " NOT NULL" : "");
sql.a(')');
if (log.isDebugEnabled())
log.debug("Creating DB table with SQL: " + sql);
GridH2RowDescriptor rowDesc = new GridH2RowDescriptor(this, tbl, tbl.type());
H2RowFactory rowFactory = tbl.rowFactory(rowDesc);
GridH2Table h2Tbl = H2TableEngine.createTable(conn, sql.toString(), rowDesc, rowFactory, tbl);
for (GridH2IndexBase usrIdx : tbl.createUserIndexes()) addInitialUserIndex(schemaName, tbl, usrIdx);
if (dataTables.putIfAbsent(h2Tbl.identifier(), h2Tbl) != null)
throw new IllegalStateException("Table already exists: " + h2Tbl.identifierString());
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor in project ignite by apache.
the class ValidateIndexesClosure method processPartIterator.
/**
* Process partition iterator.
*
* @param grpCtx Cache group context.
* @param partRes Result object.
* @param session H2 session.
* @param it Partition iterator.
* @throws IgniteCheckedException
*/
private void processPartIterator(CacheGroupContext grpCtx, ValidateIndexesPartitionResult partRes, Session session, GridIterator<CacheDataRow> it) throws IgniteCheckedException {
boolean enoughIssues = false;
GridQueryProcessor qryProcessor = ignite.context().query();
final boolean skipConditions = checkFirst > 0 || checkThrough > 0;
final boolean bothSkipConditions = checkFirst > 0 && checkThrough > 0;
long current = 0;
long processedNumber = 0;
while (it.hasNextX() && !validateCtx.isCancelled()) {
if (enoughIssues)
break;
CacheDataRow row = it.nextX();
if (skipConditions) {
if (bothSkipConditions) {
if (processedNumber > checkFirst)
break;
else if (current++ % checkThrough > 0)
continue;
else
processedNumber++;
} else {
if (checkFirst > 0) {
if (current++ > checkFirst)
break;
} else {
if (current++ % checkThrough > 0)
continue;
}
}
}
int cacheId = row.cacheId() == 0 ? grpCtx.groupId() : row.cacheId();
GridCacheContext<?, ?> cacheCtx = row.cacheId() == 0 ? grpCtx.singleCacheContext() : grpCtx.shared().cacheContext(row.cacheId());
if (cacheCtx == null)
throw new IgniteException("Unknown cacheId of CacheDataRow: " + cacheId);
if (row.link() == 0L) {
String errMsg = "Invalid partition row, possibly deleted";
log.error(errMsg);
IndexValidationIssue is = new IndexValidationIssue(null, cacheCtx.name(), null, new IgniteCheckedException(errMsg));
enoughIssues |= partRes.reportIssue(is);
continue;
}
QueryTypeDescriptorImpl res = qryProcessor.typeByValue(cacheCtx.name(), cacheCtx.cacheObjectContext(), row.key(), row.value(), true);
if (res == null)
// Tolerate - (k, v) is just not indexed.
continue;
IgniteH2Indexing indexing = (IgniteH2Indexing) qryProcessor.getIndexing();
GridH2Table gridH2Tbl = indexing.schemaManager().dataTable(cacheCtx.name(), res.tableName());
if (gridH2Tbl == null)
// Tolerate - (k, v) is just not indexed.
continue;
GridH2RowDescriptor gridH2RowDesc = gridH2Tbl.rowDescriptor();
H2CacheRow h2Row = gridH2RowDesc.createRow(row);
ArrayList<Index> indexes = gridH2Tbl.getIndexes();
for (Index idx : indexes) {
if (validateCtx.isCancelled())
break;
if (!(idx instanceof H2TreeIndexBase))
continue;
try {
Cursor cursor = idx.find(session, h2Row, h2Row);
if (cursor == null || !cursor.next())
throw new IgniteCheckedException("Key is present in CacheDataTree, but can't be found in SQL index.");
} catch (Throwable t) {
Object o = CacheObjectUtils.unwrapBinaryIfNeeded(grpCtx.cacheObjectContext(), row.key(), true, true);
IndexValidationIssue is = new IndexValidationIssue(o.toString(), cacheCtx.name(), idx.getName(), t);
log.error("Failed to lookup key: " + is.toString(), t);
enoughIssues |= partRes.reportIssue(is);
}
}
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor in project ignite by apache.
the class SchemaManager method createTable.
/**
* Create db table by using given table descriptor.
*
* @param schemaName Schema name.
* @param schema Schema.
* @param tbl Table descriptor.
* @param conn Connection.
* @throws SQLException If failed to create db table.
* @throws IgniteCheckedException If failed.
*/
private GridH2Table createTable(String schemaName, H2Schema schema, H2TableDescriptor tbl, H2PooledConnection conn) throws SQLException, IgniteCheckedException {
assert schema != null;
assert tbl != null;
String sql = H2Utils.tableCreateSql(tbl);
if (log.isDebugEnabled())
log.debug("Creating DB table with SQL: " + sql);
GridH2RowDescriptor rowDesc = new GridH2RowDescriptor(tbl, tbl.type());
GridH2Table h2Tbl = H2TableEngine.createTable(conn.connection(), sql, rowDesc, tbl, ctx.indexProcessor());
for (GridH2IndexBase usrIdx : tbl.createUserIndexes()) createInitialUserIndex(schemaName, tbl, usrIdx);
return h2Tbl;
}
Aggregations