use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteSqlQueryMinMaxTest method testMinMaxQueryPlanOnKey.
/**
* Check min() and max() over _key use correct index
* Test uses value object cache
*/
public void testMinMaxQueryPlanOnKey() throws Exception {
try (Ignite client = startGrid("client")) {
IgniteCache<Integer, ValueObj> cache = client.cache(CACHE_NAME_2);
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_key), max(_key) from ValueObj"));
List<List<?>> result = cursor.getAll();
assertEquals(2, result.size());
assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("_key_pk"));
assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("direct lookup"));
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteSqlQueryMinMaxTest method testSimpleMinMaxQueryPlanOnValue.
/**
* Check min() and max() over _val uses correct index.
* Test uses primitive cache
*/
public void testSimpleMinMaxQueryPlanOnValue() throws Exception {
try (Ignite client = startGrid("client")) {
IgniteCache<Integer, Integer> cache = client.cache(CACHE_NAME);
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_val), max(_val) from Integer"));
List<List<?>> result = cursor.getAll();
assertEquals(2, result.size());
assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("_val_idx"));
assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("direct lookup"));
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class GridMarshallerAbstractTest method testMarshallingAnonymousClassInstance.
/**
* Tests marshal anonymous class instance.
*
* @throws Exception If test failed.
*/
public void testMarshallingAnonymousClassInstance() throws Exception {
final Ignite g = grid();
GridMarshallerTestBean inBean = newTestBean(new IgniteClosure() {
/**
*/
private Iterable<ClusterNode> nodes = g.cluster().nodes();
/**
* {@inheritDoc}
*/
@Override
public Object apply(Object o) {
return nodes;
}
});
byte[] buf = marshal(inBean);
GridMarshallerTestBean outBean = unmarshal(buf);
assert inBean.getObjectField() != null;
assert outBean.getObjectField() != null;
assert IgniteClosure.class.isAssignableFrom(inBean.getObjectField().getClass());
assert IgniteClosure.class.isAssignableFrom(outBean.getObjectField().getClass());
assert inBean.getObjectField() != outBean.getObjectField();
assert inBean != outBean;
assert inBean.equals(outBean);
outBean.checkNullResources();
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteSqlQueryMinMaxTest method testJoinGroupMinMax.
/**
* Check min() and max() over group with joins
*/
public void testJoinGroupMinMax() throws Exception {
try (Ignite client = startGrid("client")) {
IgniteCache<Integer, Integer> cache = client.cache(CACHE_NAME);
IgniteCache<Integer, ValueObj> cache2 = client.cache(CACHE_NAME_2);
int count = 1_000;
int groupSize = 100;
for (int idx = 0; idx < count; ++idx) {
cache.put(idx, idx);
cache2.put(idx, new ValueObj(count - idx - 1, groupSize));
}
// join a.key = b.key, collocated
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select b.groupVal, min(a._key), max(a._key), min(a._val), max(a._val), " + "min(b._key), max(b._key), min(b.idxVal), max(b.idxVal), min(b.nonIdxVal), max(b.nonIdxVal) " + "from \"intCache\".Integer a, \"valCache\".ValueObj b where a._key = b._key " + "group by b.groupVal order by b.groupVal"));
List<List<?>> result = cursor.getAll();
assertEquals(count / groupSize, result.size());
for (int idx = 0; idx < result.size(); ++idx) {
assertEquals(idx, result.get(idx).get(0));
int min = idx * groupSize;
int max = (idx + 1) * groupSize - 1;
int revMin = count - max - 1;
int revMax = count - min - 1;
// min(a._key)
assertEquals(revMin, result.get(idx).get(1));
// max(a._key)
assertEquals(revMax, result.get(idx).get(2));
// min(a._val)
assertEquals(revMin, result.get(idx).get(3));
// max(a._val)
assertEquals(revMax, result.get(idx).get(4));
// min(b._key)
assertEquals(revMin, result.get(idx).get(5));
// max(b_key)
assertEquals(revMax, result.get(idx).get(6));
// min(b.idxVal)
assertEquals(min, result.get(idx).get(7));
// max(b.idxVal),
assertEquals(max, result.get(idx).get(8));
// min(b.nonIdxVal)
assertEquals(min, result.get(idx).get(9));
// max(b.nonIdxVal)
assertEquals(max, result.get(idx).get(10));
}
// join a.key = b.val, non-collocated
cursor = cache.query(new SqlFieldsQuery("select b.groupVal, min(a._key), max(a._key), min(a._val), max(a._val), " + "min(b._key), max(b._key), min(b.idxVal), max(b.idxVal), min(b.nonIdxVal), max(b.nonIdxVal) " + "from \"intCache\".Integer a, \"valCache\".ValueObj b where a._key = b.idxVal " + "group by b.groupVal order by b.groupVal").setDistributedJoins(true));
result = cursor.getAll();
assertEquals(count / groupSize, result.size());
for (int idx = 0; idx < result.size(); ++idx) {
assertEquals(idx, result.get(idx).get(0));
int min = idx * groupSize;
int max = (idx + 1) * groupSize - 1;
int revMin = count - max - 1;
int revMax = count - min - 1;
// min(a._key)
assertEquals(min, result.get(idx).get(1));
// max(a._key)
assertEquals(max, result.get(idx).get(2));
// min(a._val)
assertEquals(min, result.get(idx).get(3));
// max(a._val)
assertEquals(max, result.get(idx).get(4));
// min(b._key)
assertEquals(revMin, result.get(idx).get(5));
// max(b_key)
assertEquals(revMax, result.get(idx).get(6));
// min(b.idxVal)
assertEquals(min, result.get(idx).get(7));
// max(b.idxVal),
assertEquals(max, result.get(idx).get(8));
// min(b.nonIdxVal)
assertEquals(min, result.get(idx).get(9));
// max(b.nonIdxVal)
assertEquals(max, result.get(idx).get(10));
}
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteSqlQueryMinMaxTest method testSimpleMinMaxQueryPlanOnKey.
/**
* Check min() and max() over _key uses correct index
* Test uses primitive cache
*/
public void testSimpleMinMaxQueryPlanOnKey() throws Exception {
try (Ignite client = startGrid("client")) {
IgniteCache<Integer, Integer> cache = client.cache(CACHE_NAME);
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_key), max(_key) from Integer"));
List<List<?>> result = cursor.getAll();
assertEquals(2, result.size());
assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("_key_pk"));
assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("direct lookup"));
}
}
Aggregations