use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class RunningQueriesTest method testClusterWideQueryIdGeneration.
/**
* Check cluster wide query id generation.
*/
@Test
public void testClusterWideQueryIdGeneration() {
newBarrier(1);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) {
FieldsQueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("SELECT * FROM Integer WHERE 1 = 1"));
Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1);
assertEquals(1, runningQueries.size());
GridRunningQueryInfo r = runningQueries.iterator().next();
assertEquals(ignite.context().localNodeId() + "_" + r.id(), r.globalQueryId());
cursor.close();
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class RunningQueriesTest method testQueryDML.
/**
* Check tracking running queries for DML.
*
* @param dmlQry DML query.
* @throws Exception Exception in case of failure.
*/
public void testQueryDML(String dmlQry) throws Exception {
newBarrier(2);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
SqlFieldsQuery qry = new SqlFieldsQuery(dmlQry);
IgniteInternalFuture<List<List<?>>> fut = GridTestUtils.runAsync(() -> cache.query(qry).getAll());
assertWaitingOnBarrier();
Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1);
assertEquals(1, runningQueries.size());
assertNoRunningQueries(ignite);
runningQueries.forEach((info) -> Assert.assertEquals(qry.getSql(), info.query()));
IgniteInternalFuture<Integer> fut1 = GridTestUtils.runAsync(() -> barrier.await());
awaitTimeout();
fut1.get(TIMEOUT_IN_MS);
fut.get(TIMEOUT_IN_MS);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class RunningQueriesTest method testQueryDDL.
/**
* Check tracking running queries for DDL.
*
* @throws Exception Exception in case of failure.
*/
public void testQueryDDL(String sql) throws Exception {
newBarrier(2);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
SqlFieldsQuery qry = new SqlFieldsQuery(sql);
IgniteInternalFuture<List<List<?>>> fut = GridTestUtils.runAsync(() -> cache.query(qry).getAll());
assertWaitingOnBarrier();
Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1);
assertEquals(1, runningQueries.size());
assertNoRunningQueries(ignite);
runningQueries.forEach((info) -> Assert.assertEquals(qry.getSql(), info.query()));
awaitTimeout();
awaitTimeout();
fut.get(TIMEOUT_IN_MS);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlRoutingTest method testDateKeyAsTimestampParameter.
/**
*/
@Test
public void testDateKeyAsTimestampParameter() throws Exception {
String cacheName = "dateCache";
CacheConfiguration<Date, Date> ccfg = new CacheConfiguration<>(cacheName);
ccfg.setCacheMode(CacheMode.PARTITIONED);
ccfg.setIndexedTypes(Date.class, Date.class);
IgniteCache<Date, Date> cache = grid(NODE_CLIENT).createCache(ccfg);
try {
int count = 30;
Date[] values = new Date[count];
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
for (int i = 0; i < count; i++) {
Date val = dateFormat.parse(String.format("%02d/06/2017", i + 1));
cache.put(val, val);
values[i] = val;
}
for (Date val : values) {
Timestamp ts = new Timestamp(val.getTime());
List<List<?>> result = cache.query(new SqlFieldsQuery("select _val from Date where _key = ?").setArgs(ts)).getAll();
assertEquals(1, result.size());
assertEquals(val, result.get(0).get(0));
}
} finally {
cache.destroy();
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlRoutingTest method testUnicastQuerySelectAffinityKeyEqualsConstant.
/**
*/
@Test
public void testUnicastQuerySelectAffinityKeyEqualsConstant() throws Exception {
IgniteCache<CallKey, Call> cache = grid(NODE_CLIENT).cache(CACHE_CALL);
List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select id, name, duration from Call where personId=100 order by id"), 1);
assertEquals(2, result.size());
checkResultsRow(result, 0, 1, "caller1", 100);
checkResultsRow(result, 1, 2, "caller2", 200);
}
Aggregations