Search in sources :

Example 41 with Prepared

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);
}
Also used : Prepared(org.h2.command.Prepared)

Example 42 with Prepared

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);
}
Also used : Prepared(org.h2.command.Prepared)

Example 43 with Prepared

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);
}
Also used : Prepared(org.h2.command.Prepared)

Example 44 with Prepared

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);
}
Also used : Prepared(org.h2.command.Prepared)

Example 45 with Prepared

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();
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Prepared(org.h2.command.Prepared) ArrayList(java.util.ArrayList) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) GridQueryCacheObjectsIterator(org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator) GridQueryFieldsResult(org.apache.ignite.internal.processors.query.GridQueryFieldsResult) LinkedHashMap(java.util.LinkedHashMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridQueryCacheObjectsIterator(org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator) IgniteSingletonIterator(org.apache.ignite.internal.util.lang.IgniteSingletonIterator) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan)

Aggregations

Prepared (org.h2.command.Prepared)32 ValueString (org.h2.value.ValueString)16 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)11 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)11 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)11 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)10 Parameter (org.h2.expression.Parameter)10 DbException (org.h2.message.DbException)10 PreparedStatement (java.sql.PreparedStatement)9 Value (org.h2.value.Value)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)7 Query (org.h2.command.dml.Query)7 Expression (org.h2.expression.Expression)7 Column (org.h2.table.Column)7 Connection (java.sql.Connection)6 IndexColumn (org.h2.table.IndexColumn)6 ResultSet (java.sql.ResultSet)5 SQLClientInfoException (java.sql.SQLClientInfoException)5 Savepoint (java.sql.Savepoint)5