Search in sources :

Example 6 with SqlFieldsQueryEx

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

the class WarningOnBigQueryResultsTest method testDisableWarning.

/**
 */
@Test
public void testDisableWarning() throws Exception {
    setBigResultThreshold(grid(0), 0, 0);
    setBigResultThreshold(grid(1), 0, 0);
    setBigResultThreshold(grid(2), 0, 0);
    setBigResultThreshold(grid(3), 0, 0);
    assertEquals(KEYS_PER_NODE * 2, grid("cli").context().query().querySqlFields(new SqlFieldsQueryEx("SELECT * FROM TEST0", true).setSchema("TEST0"), false).getAll().size());
    assertEquals(0, listener(grid(0)).messageCount());
    assertEquals(0, listener(grid(1)).messageCount());
    assertEquals(0, listener(grid(2)).messageCount());
    assertEquals(0, listener(grid(3)).messageCount());
    assertEquals(KEYS_PER_NODE * 2, grid("cli").context().query().querySqlFields(new SqlFieldsQueryEx("SELECT * FROM TEST1", true).setSchema("TEST1"), false).getAll().size());
    assertEquals(0, listener(grid(0)).messageCount());
    assertEquals(0, listener(grid(1)).messageCount());
    assertEquals(0, listener(grid(2)).messageCount());
    assertEquals(0, listener(grid(3)).messageCount());
    setBigResultThreshold(grid(0), -1, -1);
    setBigResultThreshold(grid(1), -1, -1);
    setBigResultThreshold(grid(2), -1, -1);
    setBigResultThreshold(grid(3), -1, -1);
    assertEquals(KEYS_PER_NODE * 2, grid("cli").context().query().querySqlFields(new SqlFieldsQueryEx("SELECT * FROM TEST0", true).setSchema("TEST0"), false).getAll().size());
    assertEquals(0, listener(grid(0)).messageCount());
    assertEquals(0, listener(grid(1)).messageCount());
    assertEquals(0, listener(grid(2)).messageCount());
    assertEquals(0, listener(grid(3)).messageCount());
    assertEquals(KEYS_PER_NODE * 2, grid("cli").context().query().querySqlFields(new SqlFieldsQueryEx("SELECT * FROM TEST1", true).setSchema("TEST1"), false).getAll().size());
    assertEquals(0, listener(grid(0)).messageCount());
    assertEquals(0, listener(grid(1)).messageCount());
    assertEquals(0, listener(grid(2)).messageCount());
    assertEquals(0, listener(grid(3)).messageCount());
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) Test(org.junit.Test)

Example 7 with SqlFieldsQueryEx

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

the class JdbcPreparedStatement method parameterMetaData.

/**
 * Fetches parameters metadata of the specified query.
 */
private ParameterMetaData parameterMetaData() throws SQLException {
    SqlFieldsQueryEx qry = new SqlFieldsQueryEx(sql, null);
    setupQuery(qry);
    try {
        List<JdbcParameterMeta> params = conn.ignite().context().query().getIndexing().parameterMetaData(conn.schemaName(), qry);
        return new JdbcThinParameterMetadata(params);
    } catch (IgniteSQLException ex) {
        throw ex.toJdbcException();
    }
}
Also used : JdbcParameterMeta(org.apache.ignite.internal.processors.odbc.jdbc.JdbcParameterMeta) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) JdbcThinParameterMetadata(org.apache.ignite.internal.jdbc.thin.JdbcThinParameterMetadata)

Example 8 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method testInsertFromSelectDistinct.

/**
 */
@Test
public void testInsertFromSelectDistinct() {
    Map<Integer, Account> accounts = getAccounts(100, 2, 100);
    client.cache(CACHE_ACCOUNT).putAll(accounts);
    String text = "INSERT INTO \"list\".String (_key, _val) " + "SELECT DISTINCT sn, name FROM \"acc\".Account ";
    checkUpdate(client.<Integer, String>cache(CACHE_LIST), null, new SqlFieldsQueryEx(text, false));
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 9 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method testUpdateSetSubquery.

/**
 */
@Test
public void testUpdateSetSubquery() {
    Map<Integer, Account> accounts = getAccounts(100, 1, 1000);
    Map<Integer, Trade> trades = getTrades(100, 2);
    client.cache(CACHE_ACCOUNT).putAll(accounts);
    String text = "UPDATE \"trade\".Trade t SET qty = " + "(SELECT a.depo/t.price FROM \"acc\".Account a WHERE t.accountId = a._key)";
    checkUpdate(client.cache(CACHE_TRADE), trades, new SqlFieldsQueryEx(text, false));
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 10 with SqlFieldsQueryEx

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

the class CacheMvccSqlTxQueriesAbstractTest method testSelectProducesTransaction.

/**
 * @throws Exception If failed.
 */
@Test
public void testSelectProducesTransaction() throws Exception {
    ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT).setIndexedTypes(Integer.class, MvccTestSqlIndexValue.class);
    startGridsMultiThreaded(4);
    Random rnd = ThreadLocalRandom.current();
    Ignite node = grid(rnd.nextInt(4));
    IgniteCache<Object, Object> cache = node.cache(DEFAULT_CACHE_NAME);
    SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO MvccTestSqlIndexValue (_key, idxVal1) values (1,1),(2,2),(3,3)");
    try (FieldsQueryCursor<List<?>> cur = cache.query(qry)) {
        assertEquals(3L, cur.iterator().next().get(0));
    }
    SqlFieldsQueryEx qryEx = new SqlFieldsQueryEx("SELECT * FROM MvccTestSqlIndexValue", true);
    qryEx.setAutoCommit(false);
    try (FieldsQueryCursor<List<?>> cur = cache.query(qryEx)) {
        assertEquals(3, cur.getAll().size());
    }
    try (GridNearTxLocal tx = cache.unwrap(IgniteEx.class).context().cache().context().tm().userTx()) {
        assertNotNull(tx);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) IgniteEx(org.apache.ignite.internal.IgniteEx) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Ignite(org.apache.ignite.Ignite) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Aggregations

SqlFieldsQueryEx (org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)42 Test (org.junit.Test)23 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)17 List (java.util.List)11 ArrayList (java.util.ArrayList)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)7 BatchUpdateException (java.sql.BatchUpdateException)6 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)6 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)5 SQLException (java.sql.SQLException)4 IgniteException (org.apache.ignite.IgniteException)4 QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 BulkLoadContextCursor (org.apache.ignite.cache.query.BulkLoadContextCursor)3 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)3 IgniteLogger (org.apache.ignite.IgniteLogger)2 QueryCursor (org.apache.ignite.cache.query.QueryCursor)2 GridKernalContext (org.apache.ignite.internal.GridKernalContext)2