Search in sources :

Example 21 with SqlFieldsQuery

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

the class CacheBinaryKeyConcurrentQueryTest method startUpdate.

/**
     * @param cacheName Cache name.
     * @return Future.
     */
private IgniteInternalFuture<?> startUpdate(final String cacheName) {
    final long stopTime = System.currentTimeMillis() + 30_000;
    final AtomicInteger idx = new AtomicInteger();
    return GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Void call() {
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            IgniteCache cache = ignite(idx.getAndIncrement() % NODES).cache(cacheName).withKeepBinary();
            while (System.currentTimeMillis() < stopTime) {
                switch(rnd.nextInt(5)) {
                    case 0:
                        {
                            TestKey key = new TestKey(rnd.nextInt(KEYS));
                            CacheEntry e = cache.getEntry(key);
                            assertNotNull(e);
                            assertTrue(e.getKey() instanceof BinaryObject);
                            cache.put(e.getKey(), new TestValue(rnd.nextInt(KEYS)));
                            break;
                        }
                    case 1:
                        {
                            Iterator<Cache.Entry> it = cache.iterator();
                            for (int i = 0; i < 100 && it.hasNext(); i++) {
                                Cache.Entry e = it.next();
                                assertTrue(e.getKey() instanceof BinaryObject);
                                cache.put(e.getKey(), new TestValue(rnd.nextInt(KEYS)));
                            }
                            break;
                        }
                    case 2:
                        {
                            SqlFieldsQuery qry = new SqlFieldsQuery("select _key " + "from \"" + cache.getName() + "\".TestValue where id=?");
                            qry.setArgs(rnd.nextInt(KEYS));
                            List<List> res = cache.query(qry).getAll();
                            assertEquals(1, res.size());
                            BinaryObject key = (BinaryObject) res.get(0).get(0);
                            cache.put(key, new TestValue(rnd.nextInt(KEYS)));
                            break;
                        }
                    case 3:
                        {
                            SqlQuery qry = new SqlQuery("TestValue", "id=?");
                            qry.setArgs(rnd.nextInt(KEYS));
                            List<Cache.Entry> res = cache.query(qry).getAll();
                            assertEquals(1, res.size());
                            break;
                        }
                    case 4:
                        {
                            SqlQuery qry = new SqlQuery("TestValue", "order by id");
                            int cnt = 0;
                            for (Cache.Entry e : (Iterable<Cache.Entry>) cache.query(qry)) {
                                assertNotNull(cache.get(e.getKey()));
                                cnt++;
                            }
                            assertTrue(cnt > 0);
                            break;
                        }
                    default:
                        fail();
                }
            }
            return null;
        }
    }, NODES * 2, "test-thread");
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) IgniteCache(org.apache.ignite.IgniteCache) CacheEntry(org.apache.ignite.cache.CacheEntry) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) CacheEntry(org.apache.ignite.cache.CacheEntry) BinaryObject(org.apache.ignite.binary.BinaryObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BinaryObject(org.apache.ignite.binary.BinaryObject) List(java.util.List) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 22 with SqlFieldsQuery

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

the class CacheOffheapBatchIndexingSingleTypeTest method testBatchRemove.

/**
     * Tests removal using EntryProcessor.
     *
     * @throws Exception If failed.
     */
public void testBatchRemove() throws Exception {
    Ignite ignite = grid(0);
    CacheConfiguration<Object, Object> ccfg = cacheConfiguration(new Class<?>[] { Integer.class, CacheOffheapBatchIndexingBaseTest.Organization.class });
    final IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
    try {
        int iterations = 50;
        while (iterations-- >= 0) {
            int total = 1000;
            for (int id = 0; id < total; id++) cache.put(id, new CacheOffheapBatchIndexingBaseTest.Organization(id, "Organization " + id));
            cache.invoke(0, new CacheEntryProcessor<Object, Object, Object>() {

                @Override
                public Object process(MutableEntry<Object, Object> entry, Object... args) {
                    entry.remove();
                    return null;
                }
            });
            QueryCursor<List<?>> q = cache.query(new SqlFieldsQuery("select _key,_val from Organization where id=0"));
            assertEquals(0, q.getAll().size());
            q = cache.query(new SqlFieldsQuery("select _key,_val from Organization where id=1"));
            assertEquals(1, q.getAll().size());
            assertEquals(total - 1, cache.size());
            cache.removeAll();
        }
    } finally {
        cache.destroy();
    }
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List)

Example 23 with SqlFieldsQuery

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

the class CacheAbstractQueryMetricsSelfTest method testSqlFieldsCrossCacheQueryMetrics.

/**
     * Test metrics for SQL cross cache queries.
     *
     * @throws Exception In case of error.
     */
public void testSqlFieldsCrossCacheQueryMetrics() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
    SqlFieldsQuery qry = new SqlFieldsQuery("select * from \"B\".String");
    checkQueryMetrics(cache, qry);
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 24 with SqlFieldsQuery

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

the class CacheAbstractQueryDetailMetricsSelfTest method testSqlFieldsQueryMetrics.

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

Example 25 with SqlFieldsQuery

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

the class CacheAbstractQueryDetailMetricsSelfTest method testQueryMetricsMultithreaded.

/**
     * Test metrics if queries executed from several threads.
     *
     * @throws Exception In case of error.
     */
public void testQueryMetricsMultithreaded() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
    Collection<Worker> workers = new ArrayList<>();
    int repeat = 10;
    for (int k = 0; k < repeat; k++) {
        // Execute as match queries as history size to avoid eviction.
        for (int i = 1; i <= QRY_DETAIL_METRICS_SIZE; i++) workers.add(new Worker(cache, new SqlFieldsQuery("select * from String limit " + i)));
    }
    for (Worker worker : workers) worker.start();
    for (Worker worker : workers) worker.join();
    for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, repeat, repeat, 0, false);
}
Also used : ArrayList(java.util.ArrayList) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)197 List (java.util.List)119 ArrayList (java.util.ArrayList)59 Ignite (org.apache.ignite.Ignite)32 IgniteCache (org.apache.ignite.IgniteCache)29 CacheException (javax.cache.CacheException)24 SqlQuery (org.apache.ignite.cache.query.SqlQuery)19 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)17 Cache (javax.cache.Cache)14 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 GridRandom (org.apache.ignite.internal.util.GridRandom)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Random (java.util.Random)8 IgniteException (org.apache.ignite.IgniteException)8 BinaryObject (org.apache.ignite.binary.BinaryObject)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)6 QueryCursor (org.apache.ignite.cache.query.QueryCursor)6 IOException (java.io.IOException)5 Map (java.util.Map)5