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));
}
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));
}
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));
}
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);
}
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);
}
Aggregations