use of org.apache.ignite.cache.query.TextQuery in project ignite by apache.
the class IgniteCachePartitionedQueryMultiThreadedSelfTest method testLuceneAndSqlMultithreaded.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
@Test
public void testLuceneAndSqlMultithreaded() throws Exception {
// ---------- Test parameters ---------- //
int luceneThreads = 10;
int sqlThreads = 10;
long duration = 10 * 1000;
final int logMod = 100;
final PersonObj p1 = new PersonObj("Jon", 1500, "Master");
final PersonObj p2 = new PersonObj("Jane", 2000, "Master");
final PersonObj p3 = new PersonObj("Mike", 1800, "Bachelor");
final PersonObj p4 = new PersonObj("Bob", 1900, "Bachelor");
final IgniteCache<UUID, PersonObj> cache0 = grid(0).cache(DEFAULT_CACHE_NAME);
cache0.put(p1.id(), p1);
cache0.put(p2.id(), p2);
cache0.put(p3.id(), p3);
cache0.put(p4.id(), p4);
assertEquals(4, cache0.localSize(CachePeekMode.ALL));
assert grid(0).cluster().nodes().size() == GRID_CNT;
final AtomicBoolean done = new AtomicBoolean();
final AtomicLong luceneCnt = new AtomicLong();
// Start lucene query threads.
IgniteInternalFuture<?> futLucene = GridTestUtils.runMultiThreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
while (!done.get()) {
QueryCursor<Cache.Entry<UUID, PersonObj>> master = cache0.query(new TextQuery(PersonObj.class, "Master"));
Collection<Cache.Entry<UUID, PersonObj>> entries = master.getAll();
checkResult(entries, p1, p2);
long cnt = luceneCnt.incrementAndGet();
if (cnt % logMod == 0)
info("Executed LUCENE queries: " + cnt);
}
}
}, luceneThreads, "LUCENE-THREAD");
final AtomicLong sqlCnt = new AtomicLong();
// Start sql query threads.
IgniteInternalFuture<?> futSql = GridTestUtils.runMultiThreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
while (!done.get()) {
QueryCursor<Cache.Entry<UUID, PersonObj>> bachelors = cache0.query(new SqlQuery(PersonObj.class, "degree = 'Bachelor'"));
Collection<Cache.Entry<UUID, PersonObj>> entries = bachelors.getAll();
checkResult(entries, p3, p4);
long cnt = sqlCnt.incrementAndGet();
if (cnt % logMod == 0)
info("Executed SQL queries: " + cnt);
}
}
}, sqlThreads, "SQL-THREAD");
Thread.sleep(duration);
done.set(true);
futLucene.get();
futSql.get();
}
use of org.apache.ignite.cache.query.TextQuery in project ignite by apache.
the class IgniteCacheProxy method query.
/**
* @param filter Filter.
* @param grp Optional cluster group.
* @return Cursor.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
private QueryCursor<Cache.Entry<K, V>> query(final Query filter, @Nullable ClusterGroup grp) throws IgniteCheckedException {
final CacheQuery qry;
boolean isKeepBinary = opCtx != null && opCtx.isKeepBinary();
final CacheQueryFuture fut;
if (filter instanceof TextQuery) {
TextQuery p = (TextQuery) filter;
qry = ctx.queries().createFullTextQuery(p.getType(), p.getText(), isKeepBinary);
if (grp != null)
qry.projection(grp);
fut = ctx.kernalContext().query().executeQuery(GridCacheQueryType.TEXT, p.getText(), ctx, new IgniteOutClosureX<CacheQueryFuture<Map.Entry<K, V>>>() {
@Override
public CacheQueryFuture<Map.Entry<K, V>> applyx() {
return qry.execute();
}
}, false);
} else if (filter instanceof SpiQuery) {
qry = ctx.queries().createSpiQuery(isKeepBinary);
if (grp != null)
qry.projection(grp);
fut = ctx.kernalContext().query().executeQuery(GridCacheQueryType.SPI, filter.getClass().getSimpleName(), ctx, new IgniteOutClosureX<CacheQueryFuture<Map.Entry<K, V>>>() {
@Override
public CacheQueryFuture<Map.Entry<K, V>> applyx() {
return qry.execute(((SpiQuery) filter).getArgs());
}
}, false);
} else {
if (filter instanceof SqlFieldsQuery)
throw new CacheException("Use methods 'queryFields' and 'localQueryFields' for " + SqlFieldsQuery.class.getSimpleName() + ".");
throw new CacheException("Unsupported query type: " + filter);
}
return new QueryCursorImpl<>(new GridCloseableIteratorAdapter<Entry<K, V>>() {
/** */
private Cache.Entry<K, V> cur;
@Override
protected Entry<K, V> onNext() throws IgniteCheckedException {
if (!onHasNext())
throw new NoSuchElementException();
Cache.Entry<K, V> e = cur;
cur = null;
return e;
}
@Override
protected boolean onHasNext() throws IgniteCheckedException {
if (cur != null)
return true;
Object next = fut.next();
// instead of Iterator<Map.Entry> due to IndexingSpi interface.
if (next == null)
return false;
if (next instanceof Cache.Entry)
cur = (Cache.Entry) next;
else {
Map.Entry e = (Map.Entry) next;
cur = new CacheEntryImpl(e.getKey(), e.getValue());
}
return true;
}
@Override
protected void onClose() throws IgniteCheckedException {
fut.cancel();
}
});
}
use of org.apache.ignite.cache.query.TextQuery in project ignite by apache.
the class CacheAbstractQueryDetailMetricsSelfTest method testTextQueryNotFullyFetchedMetrics.
/**
* Test metrics for Sql queries.
*
* @throws Exception In case of error.
*/
@Test
public void testTextQueryNotFullyFetchedMetrics() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
TextQuery qry = new TextQuery<>("String", "1");
qry.setPageSize(10);
checkQueryNotFullyFetchedMetrics(cache, qry, true);
}
use of org.apache.ignite.cache.query.TextQuery in project ignite by apache.
the class SqlQueryHistorySelfTest method testTextQueryMetrics.
/**
* Test metrics for Sql queries.
*/
@Test
public void testTextQueryMetrics() {
TextQuery qry = new TextQuery<>("String", "1");
checkNoQueryMetrics(qry);
}
Aggregations