use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteCacheReplicatedFieldsQueryJoinNoPrimaryPartitionsSelfTest method testJoinNonCollocated.
/**
* Test non-colocated join.
*
* @throws Exception If failed.
*/
public void testJoinNonCollocated() throws Exception {
SqlFieldsQuery qry = new SqlFieldsQuery("SELECT COUNT(*) FROM PartValue p, RepValue r WHERE p.repId=r.id");
long cnt = (Long) grid(NODE_CLI).cache(CACHE_PARTITIONED).query(qry).getAll().get(0).get(0);
assertEquals(PART_CNT, cnt);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteCacheDistributedJoinTest method checkSameResult.
/**
* @param s Statement.
* @param c Cache.
* @param qry Query.
* @throws SQLException If failed.
*/
private <Z extends X> void checkSameResult(Statement s, IgniteCache<Integer, Z> c, String qry) throws SQLException {
s.executeUpdate("SET SCHEMA " + c.getName());
try (ResultSet rs1 = s.executeQuery(qry);
QueryCursor<List<?>> rs2 = c.query(new SqlFieldsQuery(qry).setDistributedJoins(true))) {
Iterator<List<?>> iter = rs2.iterator();
for (; ; ) {
if (!rs1.next()) {
assertFalse(iter.hasNext());
return;
}
assertTrue(iter.hasNext());
List<?> row = iter.next();
for (int i = 0; i < row.size(); i++) assertEquals(rs1.getLong(i + 1), row.get(i));
}
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlSegmentedIndexSelfTest method checkLocalQueryWithSegmentedIndex.
/**
* Test local query.
*
* @throws Exception If failed.
*/
public void checkLocalQueryWithSegmentedIndex() throws Exception {
for (int i = 0; i < nodesCount(); i++) {
final Ignite node = ignite(i);
IgniteCache<Integer, 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<Integer, Person> e : c1.localEntries()) {
final Integer orgId = e.getValue().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());
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlSegmentedIndexSelfTest method testSegmentedIndexWithEvictionPolicy.
/**
* Run tests on single-node grid
*
* @throws Exception If failed.
*/
public void testSegmentedIndexWithEvictionPolicy() throws Exception {
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 checkLocalSizeQueryWithSegmentedIndex.
/**
* Verifies that local <code>select count(*)</code> query returns a correct result.
*
* @throws Exception If failed.
*/
public void checkLocalSizeQueryWithSegmentedIndex() throws Exception {
for (int i = 0; i < nodesCount(); i++) {
final Ignite node = ignite(i);
IgniteCache<Integer, 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());
int expPersons = 0;
for (Cache.Entry<Integer, Person> e : c1.localEntries()) {
final Integer orgId = e.getValue().orgId;
if (locOrgIds.contains(orgId))
expPersons++;
}
String select0 = "select count(*) from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
List<List<?>> res = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll();
assertEquals((long) expPersons, res.get(0).get(0));
}
}
Aggregations