Search in sources :

Example 31 with SqlFieldsQueryEx

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

the class QueryParser method queryDescriptor.

/**
 * Prepare plan key.
 *
 * @param schemaName Schema name.
 * @param qry Query.
 * @return Plan key.
 */
private static QueryDescriptor queryDescriptor(String schemaName, SqlFieldsQuery qry) {
    boolean skipReducerOnUpdate = false;
    boolean batched = false;
    if (qry instanceof SqlFieldsQueryEx) {
        SqlFieldsQueryEx qry0 = (SqlFieldsQueryEx) qry;
        skipReducerOnUpdate = !qry.isLocal() && qry0.isSkipReducerOnUpdate();
        batched = qry0.isBatched();
    }
    return new QueryDescriptor(schemaName, qry.getSql(), qry.isCollocated(), qry.isDistributedJoins(), qry.isEnforceJoinOrder(), qry.isLocal(), skipReducerOnUpdate, batched, qry.getQueryInitiatorId());
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)

Example 32 with SqlFieldsQueryEx

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

the class QueryParser method queryParameters.

/**
 * Create parameters from query.
 *
 * @param qry Query.
 * @return Parameters.
 */
public QueryParameters queryParameters(SqlFieldsQuery qry) {
    NestedTxMode nestedTxMode = NestedTxMode.DEFAULT;
    boolean autoCommit = true;
    List<Object[]> batchedArgs = null;
    if (qry instanceof SqlFieldsQueryEx) {
        SqlFieldsQueryEx qry0 = (SqlFieldsQueryEx) qry;
        if (qry0.getNestedTxMode() != null)
            nestedTxMode = qry0.getNestedTxMode();
        autoCommit = qry0.isAutoCommit();
        batchedArgs = qry0.batchedArguments();
    }
    int timeout = qry.getTimeout();
    if (timeout < 0)
        timeout = (int) idx.distributedConfiguration().defaultQueryTimeout();
    return new QueryParameters(qry.getArgs(), qry.getPartitions(), timeout, qry.isLazy(), qry.getPageSize(), null, nestedTxMode, autoCommit, batchedArgs, qry.getUpdateBatchSize());
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode)

Example 33 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testQueryParallelism.

/**
 * @throws Exception if failed.
 */
@SuppressWarnings("ConstantConditions")
@Test
public void testQueryParallelism() throws Exception {
    String cacheName = CACHE_ORG + "x4";
    CacheConfiguration cfg = buildCacheConfiguration(CACHE_ORG).setQueryParallelism(4).setName(cacheName);
    IgniteCache<Integer, Organization> cache = grid(NODE_CLIENT).createCache(cfg);
    for (int i = 0; i < 1024; i++) cache.put(i, new Organization("Acme Inc #" + i, 0));
    List<List<?>> r = cache.query(new SqlFieldsQueryEx("UPDATE \"" + cacheName + "\".Organization o SET name = UPPER(name)", false).setSkipReducerOnUpdate(true)).getAll();
    assertEquals((long) cache.size(), r.get(0).get(0));
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) ArrayList(java.util.ArrayList) List(java.util.List) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 34 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method testDeleteWhereSubquery.

/**
 */
@Test
public void testDeleteWhereSubquery() {
    Map<Integer, Account> accounts = getAccounts(20, 1, 100);
    Map<Integer, Trade> trades = getTrades(10, 2);
    client.cache(CACHE_ACCOUNT).putAll(accounts);
    client.cache(CACHE_TRADE).putAll(trades);
    String text = "DELETE FROM \"acc\".Account " + "WHERE _key IN (SELECT t.accountId FROM \"trade\".Trade t)";
    checkUpdate(client.cache(CACHE_ACCOUNT), accounts, 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 35 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method testUpdateSetTableSubquery.

/**
 */
@Test
public void testUpdateSetTableSubquery() {
    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)

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