use of org.apache.ignite.cache.affinity.AffinityKey in project ignite by apache.
the class IgniteCacheAbstractFieldsQuerySelfTest method testExecuteWithMetaData.
/**
* @throws Exception If failed.
*/
@Test
public void testExecuteWithMetaData() throws Exception {
QueryCursorImpl<List<?>> cursor = (QueryCursorImpl<List<?>>) personCache.query(sqlFieldsQuery(String.format("select p._KEY, p.name, p.age, o.name " + "from \"%s\".Person p, \"%s\".Organization o where p.orgId = o.id", personCache.getName(), orgCache.getName())));
Collection<GridQueryFieldMetadata> meta = cursor.fieldsMeta();
assertNotNull(meta);
assertEquals(4, meta.size());
Iterator<GridQueryFieldMetadata> metaIt = meta.iterator();
assertNotNull(metaIt);
assert metaIt.hasNext();
GridQueryFieldMetadata field = metaIt.next();
assertNotNull(field);
assertEquals(personCache.getName(), field.schemaName());
assertEquals("PERSON", field.typeName());
assertEquals("_KEY", field.fieldName());
assertEquals(Object.class.getName(), field.fieldTypeName());
assert metaIt.hasNext();
field = metaIt.next();
assertNotNull(field);
assertEquals(personCache.getName(), field.schemaName());
assertEquals("PERSON", field.typeName());
assertEquals("NAME", field.fieldName());
assertEquals(String.class.getName(), field.fieldTypeName());
assert metaIt.hasNext();
field = metaIt.next();
assertNotNull(field);
assertEquals(personCache.getName(), field.schemaName());
assertEquals("PERSON", field.typeName());
assertEquals("AGE", field.fieldName());
assertEquals(Integer.class.getName(), field.fieldTypeName());
assert metaIt.hasNext();
field = metaIt.next();
assert field != null;
assertNotNull(field);
assertEquals(orgCache.getName(), field.schemaName());
assertEquals("ORGANIZATION", field.typeName());
assertEquals("NAME", field.fieldName());
assertEquals(String.class.getName(), field.fieldTypeName());
assert !metaIt.hasNext();
List<List<?>> res = cursor.getAll();
dedup(res);
assertEquals(3, res.size());
Collections.sort(res, new Comparator<List<?>>() {
@Override
public int compare(List<?> row1, List<?> row2) {
return ((Integer) row1.get(2)).compareTo((Integer) row2.get(2));
}
});
int cnt = 0;
for (List<?> row : res) {
assert row.size() == 4;
if (cnt == 0) {
assertEquals(new AffinityKey<>("p1", "o1"), row.get(0));
assertEquals("John White", row.get(1));
assertEquals(25, row.get(2));
assertEquals("A", row.get(3));
} else if (cnt == 1) {
assertEquals(new AffinityKey<>("p2", "o1"), row.get(0));
assertEquals("Joe Black", row.get(1));
assertEquals(35, row.get(2));
assertEquals("A", row.get(3));
}
if (cnt == 2) {
assertEquals(new AffinityKey<>("p3", "o2"), row.get(0));
assertEquals("Mike Green", row.get(1));
assertEquals(40, row.get(2));
assertEquals("B", row.get(3));
}
cnt++;
}
assertEquals(3, cnt);
}
use of org.apache.ignite.cache.affinity.AffinityKey in project ignite by apache.
the class IgniteCacheFullTextQueryNodeJoiningSelfTest method testFullTextQueryNodeJoin.
/**
* @throws Exception If failed.
*/
@Test
public void testFullTextQueryNodeJoin() throws Exception {
for (int r = 0; r < 5; r++) {
startGrids(GRID_CNT);
try {
for (int i = 0; i < 1000; i++) {
IndexedEntity entity = new IndexedEntity("indexed " + i);
grid(0).cache(DEFAULT_CACHE_NAME).put(new AffinityKey<>(i, i), entity);
}
Ignite started = startGrid(GRID_CNT);
for (int i = 0; i < 100; i++) {
QueryCursor<Cache.Entry<AffinityKey<Integer>, IndexedEntity>> res = started.cache(DEFAULT_CACHE_NAME).query(new TextQuery<AffinityKey<Integer>, IndexedEntity>(IndexedEntity.class, "indexed"));
assertEquals("Failed iteration: " + i, 1000, res.getAll().size());
}
} finally {
stopAllGrids();
}
}
}
use of org.apache.ignite.cache.affinity.AffinityKey in project ignite by apache.
the class IgniteSqlSplitterSelfTest method testSubQueryWithAggregate.
/**
*/
@Test
public void testSubQueryWithAggregate() {
CacheConfiguration ccfg1 = cacheConfig("pers", true, AffinityKey.class, Person2.class);
IgniteCache<AffinityKey<Integer>, Person2> c1 = ignite(0).getOrCreateCache(ccfg1);
try {
int orgId = 100500;
c1.put(new AffinityKey<>(1, orgId), new Person2(orgId, "Vasya"));
c1.put(new AffinityKey<>(2, orgId), new Person2(orgId, "Another Vasya"));
List<List<?>> rs = c1.query(new SqlFieldsQuery("select name, " + "select count(1) from Person2 q where q.orgId = p.orgId " + "from Person2 p order by name desc")).getAll();
assertEquals(2, rs.size());
assertEquals("Vasya", rs.get(0).get(0));
assertEquals(2L, rs.get(0).get(1));
assertEquals("Another Vasya", rs.get(1).get(0));
assertEquals(2L, rs.get(1).get(1));
} finally {
c1.destroy();
}
}
use of org.apache.ignite.cache.affinity.AffinityKey in project ignite by apache.
the class CacheQueryExample method sqlFieldsQueryWithJoin.
/**
* Example for SQL-based fields queries that return only required
* fields instead of whole key-value pairs.
*/
private static void sqlFieldsQueryWithJoin() {
IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
// Execute query to get names of all employees.
String sql = "select concat(firstName, ' ', lastName), org.name " + "from Person, \"" + ORG_CACHE + "\".Organization as org " + "where Person.orgId = org.id";
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(sql));
// In this particular case each row will have one element with full name of an employees.
List<List<?>> res = cursor.getAll();
// Print persons' names and organizations' names.
print("Names of all employees and organizations they belong to: ", res);
}
use of org.apache.ignite.cache.affinity.AffinityKey in project ignite by apache.
the class SqlQueriesExample method sqlFieldsQueryWithJoin.
/**
* Example for SQL-based fields queries that return only required
* fields instead of whole key-value pairs.
*/
private static void sqlFieldsQueryWithJoin() {
IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
// Execute query to get names of all employees.
String sql = "select concat(firstName, ' ', lastName), org.name " + "from Person, \"" + ORG_CACHE + "\".Organization as org " + "where Person.orgId = org.id";
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(sql));
// In this particular case each row will have one element with full name of an employees.
List<List<?>> res = cursor.getAll();
// Print persons' names and organizations' names.
print("Names of all employees and organizations they belong to: ", res);
}
Aggregations