Search in sources :

Example 11 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testDistributedUpdateFail.

/**
 * @throws Exception if failed.
 */
@Test
public void testDistributedUpdateFail() throws Exception {
    fillCaches();
    final IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_PERSON);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() {
            return cache.query(new SqlFieldsQueryEx("UPDATE Person SET name = Fail(name)", false).setSkipReducerOnUpdate(true));
        }
    }, CacheException.class, "Failed to run SQL update query.");
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) IgniteCache(org.apache.ignite.IgniteCache) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 12 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testSpecificPartitionsUpdate.

/**
 * @throws Exception if failed.
 */
@Test
public void testSpecificPartitionsUpdate() throws Exception {
    fillCaches();
    Affinity aff = grid(NODE_CLIENT).affinity(CACHE_PERSON);
    int numParts = aff.partitions();
    int[] parts = new int[numParts / 2];
    for (int idx = 0; idx < numParts / 2; idx++) parts[idx] = idx * 2;
    IgniteCache<PersonKey, Person> cache = grid(NODE_CLIENT).cache(CACHE_PERSON);
    // UPDATE over even partitions
    cache.query(new SqlFieldsQueryEx("UPDATE Person SET position = 0", false).setSkipReducerOnUpdate(true).setPartitions(parts));
    List<List<?>> rows = cache.query(new SqlFieldsQuery("SELECT _key, position FROM Person")).getAll();
    for (List<?> row : rows) {
        PersonKey personKey = (PersonKey) row.get(0);
        int pos = ((Number) row.get(1)).intValue();
        int part = aff.partition(personKey);
        assertTrue((part % 2 == 0) ^ (pos != 0));
    }
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) Affinity(org.apache.ignite.cache.affinity.Affinity) ArrayList(java.util.ArrayList) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 13 with SqlFieldsQueryEx

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

the class AbstractQueryTableLockAndConnectionPoolSelfTest method checkTablesLockQueryAndDDLMultithreaded.

/**
 * @param node Ignite node to execute query.
 * @throws Exception If failed.
 */
private void checkTablesLockQueryAndDDLMultithreaded(final Ignite node) throws Exception {
    final AtomicBoolean end = new AtomicBoolean(false);
    final int qryThreads = 10;
    // Do many concurrent queries.
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

        @Override
        public void run() {
            while (!end.get()) {
                try {
                    FieldsQueryCursor<List<?>> cursor = execute(node, new SqlFieldsQueryEx("SELECT pers.id, pers.name " + "FROM (SELECT DISTINCT p.id, p.name " + "FROM \"pers\".PERSON as p) as pers " + "JOIN \"pers\".PERSON p on p.id = pers.id " + "JOIN (SELECT t.persId as persId, SUM(t.time) totalTime " + "FROM \"persTask\".PersonTask as t GROUP BY t.persId) as task ON task.persId = pers.id", true).setLazy(lazy()).setLocal(local).setPageSize(PAGE_SIZE_SMALL));
                    cursor.getAll();
                } catch (Exception e) {
                    if (X.cause(e, QueryRetryException.class) == null) {
                        log.error("Unexpected exception", e);
                        fail("Unexpected exception. " + e);
                    } else if (!lazy()) {
                        log.error("Unexpected exception", e);
                        fail("Unexpected QueryRetryException.");
                    }
                }
            }
        }
    }, qryThreads, "usr-qry");
    long tEnd = U.currentTimeMillis() + TEST_DUR;
    while (U.currentTimeMillis() < tEnd) {
        execute(node, new SqlFieldsQuery("CREATE INDEX \"pers\".PERSON_NAME ON \"pers\".Person (name asc)")).getAll();
        execute(node, new SqlFieldsQuery("DROP INDEX \"pers\".PERSON_NAME")).getAll();
    }
    // Test is OK in case DDL operations is passed on hi load queries pressure.
    end.set(true);
    fut.get();
    checkConnectionLeaks(Ignition.allGrids().size());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 14 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testSimpleUpdateDistributedPartitioned.

/**
 * @throws Exception if failed.
 */
@Test
public void testSimpleUpdateDistributedPartitioned() throws Exception {
    fillCaches();
    IgniteCache<PersonKey, Person> cache = grid(NODE_CLIENT).cache(CACHE_PERSON);
    List<List<?>> r = cache.query(new SqlFieldsQueryEx("UPDATE Person SET position = CASEWHEN(position = 1, 1, position - 1)", 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) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 15 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testDistributedUpdateFailedKeys.

/**
 * @throws Exception if failed.
 */
@Test
public void testDistributedUpdateFailedKeys() throws Exception {
    // UPDATE can produce failed keys due to concurrent modification
    fillCaches();
    final IgniteCache<Integer, Organization> cache = grid(NODE_CLIENT).cache(CACHE_ORG);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() {
            return cache.query(new SqlFieldsQueryEx("UPDATE Organization SET rate = Modify(_key, rate - 1)", false).setSkipReducerOnUpdate(true));
        }
    }, CacheException.class, "Failed to update some keys because they had been modified concurrently");
}
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