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.
*/
public void checkLocalSizeQueryWithSegmentedIndex() {
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());
int expPersons = 0;
for (Cache.Entry<PersonKey, Person> e : c1.localEntries()) {
final Integer orgId = e.getKey().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));
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class SqlSchemaSelfTest method testQueryWithoutCacheOnCacheSchema.
/**
* Test query without caches.
*
* @throws Exception If failed.
*/
@Test
public void testQueryWithoutCacheOnCacheSchema() throws Exception {
node.createCache(new CacheConfiguration<PersonKey, Person>().setName(CACHE_PERSON).setIndexedTypes(PersonKey.class, Person.class));
GridQueryProcessor qryProc = node.context().query();
SqlFieldsQuery qry = new SqlFieldsQuery("SELECT 1").setSchema(CACHE_PERSON);
List<List<?>> res = qryProc.querySqlFields(qry, true).getAll();
assertEquals(1, res.size());
assertEquals(1, res.get(0).size());
assertEquals(1, res.get(0).get(0));
Iterator<List<?>> iter = qryProc.querySqlFields(qry, true).iterator();
assertTrue(iter.hasNext());
List<?> row = iter.next();
assertEquals(1, row.size());
assertEquals(1, row.get(0));
assertFalse(iter.hasNext());
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class SqlSchemaSelfTest method testSchemaChangeOnCacheWithPublicSchema.
/**
* Test simple query.
*
* @throws Exception If failed.
*/
@Test
public void testSchemaChangeOnCacheWithPublicSchema() throws Exception {
IgniteCache<PersonKey, Person> cache = node.createCache(new CacheConfiguration<PersonKey, Person>().setName(CACHE_PERSON).setIndexedTypes(PersonKey.class, Person.class).setSqlSchema(QueryUtils.DFLT_SCHEMA));
node.createCache(new CacheConfiguration<PersonKey, Person>().setName(CACHE_PERSON_2).setIndexedTypes(PersonKey.class, Person.class));
cache.put(new PersonKey(1), new Person("Vasya", 2));
// Normal calls.
assertEquals(1, cache.query(new SqlFieldsQuery("SELECT id, name, orgId FROM Person")).getAll().size());
assertEquals(1, cache.query(new SqlFieldsQuery("SELECT id, name, orgId FROM Person").setSchema(QueryUtils.DFLT_SCHEMA)).getAll().size());
// Call from another schema.
assertEquals(1, cache.query(new SqlFieldsQuery("SELECT id, name, orgId FROM public.Person").setSchema(CACHE_PERSON_2)).getAll().size());
assertEquals(1, cache.query(new SqlFieldsQuery("SELECT id, name, orgId FROM \"PUBLIC\".Person").setSchema(CACHE_PERSON_2)).getAll().size());
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class MultipleStatementsSqlQuerySelfTest method sql.
/**
* @param sql SQL query.
* @return Results.
*/
private List<FieldsQueryCursor<List<?>>> sql(String sql) {
GridQueryProcessor qryProc = node.context().query();
SqlFieldsQuery qry = new SqlFieldsQuery(sql).setSchema("PUBLIC");
return qryProc.querySqlFields(qry, true, false);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class SqlQueriesTopologyMappingTest method testLocalCacheQueryMapping.
/**
*/
@Test
public void testLocalCacheQueryMapping() throws Exception {
IgniteEx ign0 = startGrid(0);
IgniteCache<Object, Object> cache = ign0.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setCacheMode(CacheMode.LOCAL).setSqlSchema("PUBLIC").setIndexedTypes(Integer.class, Integer.class));
cache.put(1, 2);
startGrid(1);
SqlFieldsQuery qry = new SqlFieldsQuery("select * from Integer");
{
List<List<?>> res0 = grid(0).cache(DEFAULT_CACHE_NAME).query(qry).getAll();
assertEquals(1, res0.size());
assertEqualsCollections(Arrays.asList(1, 2), res0.get(0));
}
{
List<List<?>> res1 = grid(1).cache(DEFAULT_CACHE_NAME).query(qry).getAll();
assertTrue(res1.isEmpty());
}
}
Aggregations