Search in sources :

Example 6 with TextQuery

use of org.apache.ignite.cache.query.TextQuery in project ignite by apache.

the class CacheAbstractQueryDetailMetricsSelfTest method testTextQueryMetrics.

/**
     * Test metrics for Sql queries.
     *
     * @throws Exception In case of error.
     */
public void testTextQueryMetrics() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
    TextQuery qry = new TextQuery<>("String", "1");
    checkQueryMetrics(cache, qry);
}
Also used : TextQuery(org.apache.ignite.cache.query.TextQuery)

Example 7 with TextQuery

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();
        }
    });
}
Also used : IgniteOutClosureX(org.apache.ignite.internal.util.lang.IgniteOutClosureX) CacheException(javax.cache.CacheException) SpiQuery(org.apache.ignite.cache.query.SpiQuery) CacheQueryFuture(org.apache.ignite.internal.processors.cache.query.CacheQueryFuture) CacheQuery(org.apache.ignite.internal.processors.cache.query.CacheQuery) TextQuery(org.apache.ignite.cache.query.TextQuery) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) CacheEntry(org.apache.ignite.cache.CacheEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 8 with TextQuery

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.
     */
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);
}
Also used : TextQuery(org.apache.ignite.cache.query.TextQuery)

Aggregations

TextQuery (org.apache.ignite.cache.query.TextQuery)8 Cache (javax.cache.Cache)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 Collection (java.util.Collection)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 UUID (java.util.UUID)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CacheException (javax.cache.CacheException)1 CacheEntry (org.apache.ignite.cache.CacheEntry)1 QueryCursor (org.apache.ignite.cache.query.QueryCursor)1 SpiQuery (org.apache.ignite.cache.query.SpiQuery)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 SqlQuery (org.apache.ignite.cache.query.SqlQuery)1 CacheQuery (org.apache.ignite.internal.processors.cache.query.CacheQuery)1 CacheQueryFuture (org.apache.ignite.internal.processors.cache.query.CacheQueryFuture)1 IgniteOutClosureX (org.apache.ignite.internal.util.lang.IgniteOutClosureX)1 CAX (org.apache.ignite.internal.util.typedef.CAX)1