use of org.h2.test.db.Db.Prepared in project ignite by apache.
the class GridQueryParsingTest method assertCreateIndexEquals.
/**
* Parse SQL and compare it to expected instance.
*/
private void assertCreateIndexEquals(GridSqlCreateIndex exp, String sql) throws Exception {
Prepared prepared = parse(sql);
GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
assertTrue(stmt instanceof GridSqlCreateIndex);
assertCreateIndexEquals(exp, (GridSqlCreateIndex) stmt);
}
use of org.h2.test.db.Db.Prepared in project ignite by apache.
the class GridQueryParsingTest method assertDropTableEquals.
/**
* Parse SQL and compare it to expected instance of DROP TABLE.
*/
private void assertDropTableEquals(GridSqlDropTable exp, String sql) throws Exception {
Prepared prepared = parse(sql);
GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
assertTrue(stmt instanceof GridSqlDropTable);
assertDropTableEquals(exp, (GridSqlDropTable) stmt);
}
use of org.h2.test.db.Db.Prepared in project ignite by apache.
the class GridQueryParsingTest method assertCreateTableEquals.
/**
* Parse SQL and compare it to expected instance of DROP TABLE.
*/
private void assertCreateTableEquals(GridSqlCreateTable exp, String sql) throws Exception {
Prepared prepared = parse(sql);
GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
assertTrue(stmt instanceof GridSqlCreateTable);
assertCreateTableEquals(exp, (GridSqlCreateTable) stmt);
}
use of org.h2.test.db.Db.Prepared in project ignite by apache.
the class GridQueryParsingTest method assertDropIndexEquals.
/**
* Parse SQL and compare it to expected instance of DROP INDEX.
*/
private void assertDropIndexEquals(GridSqlDropIndex exp, String sql) throws Exception {
Prepared prepared = parse(sql);
GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
assertTrue(stmt instanceof GridSqlDropIndex);
assertDropIndexEquals(exp, (GridSqlDropIndex) stmt);
}
use of org.h2.test.db.Db.Prepared in project ignite by apache.
the class DmlStatementsProcessor method streamUpdateQuery.
/**
* Perform given statement against given data streamer. Only rows based INSERT is supported.
*
* @param schemaName Schema name.
* @param streamer Streamer to feed data to.
* @param stmt Statement.
* @param args Statement arguments.
* @return Number of rows in given INSERT statement.
* @throws IgniteCheckedException if failed.
*/
@SuppressWarnings({ "unchecked", "ConstantConditions" })
long streamUpdateQuery(String schemaName, IgniteDataStreamer streamer, PreparedStatement stmt, final Object[] args) throws IgniteCheckedException {
idx.checkStatementStreamable(stmt);
Prepared p = GridSqlQueryParser.prepared(stmt);
assert p != null;
final UpdatePlan plan = getPlanForStatement(schemaName, null, p, null, true, null);
assert plan.isLocalSubquery();
final GridCacheContext cctx = plan.cacheContext();
QueryCursorImpl<List<?>> cur;
final ArrayList<List<?>> data = new ArrayList<>(plan.rowCount());
QueryCursorImpl<List<?>> stepCur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
try {
Iterator<List<?>> it;
if (!F.isEmpty(plan.selectQuery())) {
GridQueryFieldsResult res = idx.queryLocalSqlFields(idx.schema(cctx.name()), plan.selectQuery(), F.asList(U.firstNotNull(args, X.EMPTY_OBJECT_ARRAY)), null, false, 0, null);
it = res.iterator();
} else
it = plan.createRows(U.firstNotNull(args, X.EMPTY_OBJECT_ARRAY)).iterator();
return new GridQueryCacheObjectsIterator(it, idx.objectContext(), cctx.keepBinary());
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
}, null);
data.addAll(stepCur.getAll());
cur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
return data.iterator();
}
}, null);
if (plan.rowCount() == 1) {
IgniteBiTuple t = plan.processRow(cur.iterator().next());
streamer.addData(t.getKey(), t.getValue());
return 1;
}
Map<Object, Object> rows = new LinkedHashMap<>(plan.rowCount());
for (List<?> row : cur) {
final IgniteBiTuple t = plan.processRow(row);
rows.put(t.getKey(), t.getValue());
}
streamer.addData(rows);
return rows.size();
}
Aggregations