use of org.apache.ignite.internal.processors.query.GridQueryProcessor in project ignite by apache.
the class CacheSqlQueryValueCopySelfTest method testRunningSqlQuery.
/**
* Test collecting info about running.
*
* @throws Exception If failed.
*/
public void testRunningSqlQuery() throws Exception {
IgniteInternalFuture<?> fut = runQueryAsync(new SqlQuery<Integer, Value>(Value.class, "id > sleep(100)"));
Thread.sleep(500);
GridQueryProcessor qryProc = grid(0).context().query();
Collection<GridRunningQueryInfo> queries = qryProc.runningQueries(0);
assertEquals(1, queries.size());
fut.get();
queries = qryProc.runningQueries(0);
assertEquals(0, queries.size());
SqlQuery<Integer, Value> qry = new SqlQuery<>(Value.class, "id > sleep(100)");
qry.setLocal(true);
fut = runQueryAsync(qry);
Thread.sleep(500);
queries = qryProc.runningQueries(0);
assertEquals(1, queries.size());
fut.get();
queries = qryProc.runningQueries(0);
assertEquals(0, queries.size());
}
use of org.apache.ignite.internal.processors.query.GridQueryProcessor in project ignite by apache.
the class GridCacheCrossCacheQuerySelfTest method testTwoStepGroupAndAggregates.
/**
* @throws Exception If failed.
*/
public void testTwoStepGroupAndAggregates() throws Exception {
IgniteInternalCache<Integer, FactPurchase> cache = ((IgniteKernal) ignite).getCache("partitioned");
GridQueryProcessor qryProc = ((IgniteKernal) ignite).context().query();
Set<Integer> set1 = new HashSet<>();
X.println("___ simple");
SqlFieldsQuery qry = new SqlFieldsQuery("select f.productId, p.name, f.price " + "from FactPurchase f, \"replicated-prod\".DimProduct p where p.id = f.productId ");
for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
X.println("___ -> " + o);
set1.add((Integer) o.get(0));
}
assertFalse(set1.isEmpty());
Set<Integer> set0 = new HashSet<>();
X.println("___ GROUP BY");
qry = new SqlFieldsQuery("select productId from FactPurchase group by productId");
for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
X.println("___ -> " + o);
assertTrue(set0.add((Integer) o.get(0)));
}
assertEquals(set0, set1);
X.println("___ GROUP BY AVG MIN MAX SUM COUNT(*) COUNT(x) (MAX - MIN) * 2 as");
Set<String> names = new HashSet<>();
qry = new SqlFieldsQuery("select p.name, avg(f.price), min(f.price), max(f.price), sum(f.price), count(*), " + "count(nullif(f.price, 5)), (max(f.price) - min(f.price)) * 3 as nn " + ", CAST(max(f.price) + 7 AS VARCHAR) " + "from FactPurchase f, \"replicated-prod\".DimProduct p " + "where p.id = f.productId " + "group by f.productId, p.name");
for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
X.println("___ -> " + o);
assertTrue(names.add((String) o.get(0)));
assertEquals(i(o, 4), i(o, 2) + i(o, 3));
assertEquals(i(o, 7), (i(o, 3) - i(o, 2)) * 3);
assertEquals(o.get(8), Integer.toString(i(o, 3) + 7));
}
X.println("___ SUM HAVING");
qry = new SqlFieldsQuery("select p.name, sum(f.price) s " + "from FactPurchase f, \"replicated-prod\".DimProduct p " + "where p.id = f.productId " + "group by f.productId, p.name " + "having s >= 15");
for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
X.println("___ -> " + o);
assertTrue(i(o, 1) >= 15);
}
X.println("___ DISTINCT ORDER BY TOP");
int top = 6;
qry = new SqlFieldsQuery("select top 3 distinct productId " + "from FactPurchase f order by productId desc ");
for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
X.println("___ -> " + o);
assertEquals(top--, o.get(0));
}
X.println("___ DISTINCT ORDER BY OFFSET LIMIT");
top = 5;
qry = new SqlFieldsQuery("select distinct productId " + "from FactPurchase f order by productId desc limit 2 offset 1");
for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
X.println("___ -> " + o);
assertEquals(top--, o.get(0));
}
assertEquals(3, top);
}
Aggregations