use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlRoutingTest method testUnicastQueryAffinityKeyTypeConversionConstant.
/**
*/
@Test
public void testUnicastQueryAffinityKeyTypeConversionConstant() throws Exception {
IgniteCache<CallKey, Call> cache = grid(NODE_CLIENT).cache(CACHE_CALL);
// Use string within expression against integer key
List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select id, name, duration from Call where personId='100' order by id"), 1);
assertEquals(2, result.size());
checkResultsRow(result, 0, 1, "caller1", 100);
checkResultsRow(result, 1, 2, "caller2", 200);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlRoutingTest method runQueryEnsureUnicast.
/**
* Run query and check that only one node did generate 'query executed' event for it.
*/
private List<List<?>> runQueryEnsureUnicast(IgniteCache<?, ?> cache, SqlFieldsQuery qry, int nodeCnt) throws Exception {
try (EventCounter evtCounter = new EventCounter(nodeCnt)) {
List<List<?>> result = cache.query(qry).getAll();
// do broadcast 'marker' query to ensure that we received all events from previous qry
cache.query(new SqlFieldsQuery(MessageFormat.format(FINAL_QRY, cache.getName())).setArgs(FINAL_QRY_PARAM)).getAll();
// wait for all events from 'marker' query
evtCounter.await();
// return result set of first query
return result;
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlRoutingTest method testUnicastQueryKeyTypeConversionConstant.
/**
*/
@Test
public void testUnicastQueryKeyTypeConversionConstant() throws Exception {
IgniteCache<Integer, Person> cache = grid(NODE_CLIENT).cache(CACHE_PERSON);
// Use string within expression against integer key
List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select name, age from Person where _key = '5'"), 1);
Person person = cache.get(5);
assertEquals(1, result.size());
assertEquals(person.name, result.get(0).get(0));
assertEquals(person.age, result.get(0).get(1));
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlSegmentedIndexSelfTest method testSegmentedIndexWithEvictionPolicy.
/**
* Run tests on single-node grid.
*/
@SuppressWarnings("deprecation")
@Test
public void testSegmentedIndexWithEvictionPolicy() {
final IgniteCache<Object, Object> cache = ignite(0).createCache(cacheConfig(ORG_CACHE_NAME, true, Integer.class, Organization.class).setEvictionPolicy(new FifoEvictionPolicy(10)).setOnheapCacheEnabled(true));
final long SIZE = 20;
for (int i = 0; i < SIZE; i++) cache.put(i, new Organization("org-" + i));
String select0 = "select name from \"org\".Organization";
List<List<?>> res = cache.query(new SqlFieldsQuery(select0)).getAll();
assertEquals(SIZE, res.size());
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlSegmentedIndexSelfTest method checkLocalQueryWithSegmentedIndex.
/**
* Test local query.
*/
public void checkLocalQueryWithSegmentedIndex() {
for (int i = 0; i < nodesCount(); i++) {
final Ignite node = ignite(i);
IgniteCache<PersonKey, Person> c1 = node.cache(PERSON_CAHE_NAME);
IgniteCache<Integer, Organization> c2 = node.cache(ORG_CACHE_NAME);
Set<Integer> locOrgIds = new HashSet<>();
for (Cache.Entry<Integer, Organization> e : c2.localEntries()) locOrgIds.add(e.getKey());
long expPersons = 0;
for (Cache.Entry<PersonKey, Person> e : c1.localEntries()) {
final Integer orgId = e.getKey().orgId;
if (locOrgIds.contains(orgId))
expPersons++;
}
String select0 = "select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
List<List<?>> res = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll();
assertEquals(expPersons, res.size());
}
}
Aggregations