Search in sources :

Example 36 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method testInsertFromSelectGroupBy.

/**
 */
@Test
public void testInsertFromSelectGroupBy() {
    Map<Integer, Account> accounts = getAccounts(100, 1, 1000);
    Map<Integer, Trade> trades = getTrades(100, 2);
    client.cache(CACHE_ACCOUNT).putAll(accounts);
    client.cache(CACHE_TRADE).putAll(trades);
    String text = "INSERT INTO \"rep\".Report (_key, accountId, spends, count) " + "SELECT accountId, accountId, SUM(qty * price), COUNT(*) " + "FROM \"trade\".Trade " + "GROUP BY accountId";
    checkUpdate(client.<Integer, Report>cache(CACHE_REPORT), 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 37 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method testMergeFromSelectGroupBy.

/**
 */
@Test
public void testMergeFromSelectGroupBy() {
    Map<Integer, Account> accounts = getAccounts(100, 1, 1000);
    Map<Integer, Trade> trades = getTrades(100, 2);
    client.cache(CACHE_ACCOUNT).putAll(accounts);
    client.cache(CACHE_TRADE).putAll(trades);
    Map<Integer, Report> reports = new HashMap<>();
    reports.put(5, new Report(5, 1, 1));
    String text = "MERGE INTO \"rep\".Report (_key, accountId, spends, count) " + "SELECT accountId, accountId, SUM(qty * price), COUNT(*) " + "FROM \"trade\".Trade " + "GROUP BY accountId";
    checkUpdate(client.<Integer, Report>cache(CACHE_REPORT), reports, new SqlFieldsQueryEx(text, false));
}
Also used : HashMap(java.util.HashMap) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 38 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlFlagSelfTest method testInsertFromSelectUnion.

/**
 */
@Test
public void testInsertFromSelectUnion() {
    Map<Integer, Account> accounts = getAccounts(20, 1, 1000);
    client.cache(CACHE_ACCOUNT).putAll(accounts);
    String text = "INSERT INTO \"trade\".Trade (_key, accountId, stockId, qty, price) " + "SELECT a._key, a._key, 0, a.depo, 1 FROM \"acc\".Account a " + "UNION " + "SELECT 101 + a2._key, a2._key, 1, a2.depo, 1 FROM \"acc\".Account a2";
    checkUpdate(client.<Integer, Trade>cache(CACHE_TRADE), 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 39 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testSimpleUpdateDistributedReplicated.

/**
 * @throws Exception if failed.
 */
@Test
public void testSimpleUpdateDistributedReplicated() throws Exception {
    fillCaches();
    IgniteCache<Integer, Position> cache = grid(NODE_CLIENT).cache(CACHE_POSITION);
    Position p = cache.get(1);
    List<List<?>> r = cache.query(new SqlFieldsQueryEx("UPDATE Position p SET name = CONCAT('A ', name)", false).setSkipReducerOnUpdate(true)).getAll();
    assertEquals((long) cache.size(), r.get(0).get(0));
    assertEquals(cache.get(1).name, "A " + p.name);
}
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 40 with SqlFieldsQueryEx

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

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testEvents.

/**
 * @throws Exception if failed.
 */
@Test
public void testEvents() throws Exception {
    final CountDownLatch latch = new CountDownLatch(NODE_COUNT);
    final IgnitePredicate<Event> pred = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            assert evt instanceof CacheQueryExecutedEvent;
            CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
            assertNotNull(qe.clause());
            latch.countDown();
            return true;
        }
    };
    for (int idx = 0; idx < NODE_COUNT; idx++) grid(idx).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED);
    IgniteCache<Integer, Organization> cache = grid(NODE_CLIENT).cache(CACHE_ORG);
    for (int i = 0; i < 1024; i++) cache.put(i, new Organization("Acme Inc #" + i, 0));
    cache.query(new SqlFieldsQueryEx("UPDATE \"org\".Organization o SET name = UPPER(name)", false).setSkipReducerOnUpdate(true)).getAll();
    assertTrue(latch.await(5000, MILLISECONDS));
    for (int idx = 0; idx < NODE_COUNT; idx++) grid(idx).events().stopLocalListen(pred);
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Event(org.apache.ignite.events.Event) CountDownLatch(java.util.concurrent.CountDownLatch) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) 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