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