Search in sources :

Example 26 with QueryCursorImpl

use of org.apache.ignite.internal.processors.cache.QueryCursorImpl in project ignite by apache.

the class MultipleStatementsSqlQuerySelfTest method testQuery.

/**
 * Test query without caches.
 */
@Test
public void testQuery() {
    GridQueryProcessor qryProc = node.context().query();
    SqlFieldsQuery qry = new SqlFieldsQuery("create table test(ID int primary key, NAME varchar(20)); " + "insert into test (ID, NAME) values (1, 'name_1');" + "insert into test (ID, NAME) values (2, 'name_2'), (3, 'name_3');" + "select * from test;").setSchema("PUBLIC");
    List<FieldsQueryCursor<List<?>>> res = qryProc.querySqlFields(qry, true, false);
    assert res.size() == 4 : "Unexpected cursors count: " + res.size();
    assert !((QueryCursorImpl) res.get(0)).isQuery() : "Results of DDL statement is expected ";
    List<List<?>> rows = res.get(1).getAll();
    assert !((QueryCursorImpl) res.get(1)).isQuery() : "Results of DDL statement is expected ";
    assert Long.valueOf(1).equals(rows.get(0).get(0)) : "1 row must be updated. [actual=" + rows.get(0).get(0) + ']';
    rows = res.get(2).getAll();
    assert !((QueryCursorImpl) res.get(2)).isQuery() : "Results of DML statement is expected ";
    assert Long.valueOf(2).equals(rows.get(0).get(0)) : "2 row must be updated";
    rows = res.get(3).getAll();
    assert ((QueryCursorImpl) res.get(3)).isQuery() : "Results of SELECT statement is expected ";
    assert rows.size() == 3 : "Invalid rows count: " + rows.size();
    for (int i = 0; i < rows.size(); ++i) {
        assert Integer.valueOf(1).equals(rows.get(i).get(0)) || Integer.valueOf(2).equals(rows.get(i).get(0)) || Integer.valueOf(3).equals(rows.get(i).get(0)) : "Invalid ID: " + rows.get(i).get(0);
    }
}
Also used : FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) List(java.util.List) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 27 with QueryCursorImpl

use of org.apache.ignite.internal.processors.cache.QueryCursorImpl in project ignite by apache.

the class H2Utils method zeroCursor.

/**
 * @return Single-column, single-row cursor with 0 as number of updated records.
 */
@SuppressWarnings("unchecked")
public static QueryCursorImpl<List<?>> zeroCursor() {
    QueryCursorImpl<List<?>> resCur = (QueryCursorImpl<List<?>>) new QueryCursorImpl(Collections.singletonList(Collections.singletonList(0L)), null, false, false);
    resCur.fieldsMeta(UPDATE_RESULT_META);
    return resCur;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl)

Aggregations

QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)27 List (java.util.List)24 ArrayList (java.util.ArrayList)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)13 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)11 IgniteException (org.apache.ignite.IgniteException)10 GridQueryCacheObjectsIterator (org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator)9 SQLException (java.sql.SQLException)8 Iterator (java.util.Iterator)8 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)6 GridQueryFieldsResult (org.apache.ignite.internal.processors.query.GridQueryFieldsResult)6 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)5 GridQueryCancel (org.apache.ignite.internal.processors.query.GridQueryCancel)5 LinkedHashMap (java.util.LinkedHashMap)4 Cache (javax.cache.Cache)4 CacheException (javax.cache.CacheException)4 SqlFieldsQueryEx (org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)4 UpdatePlan (org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan)4 GridEmptyCloseableIterator (org.apache.ignite.internal.util.GridEmptyCloseableIterator)4