Search in sources :

Example 86 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteSqlQueryMinMaxTest method testMinMaxQueryPlanOnKey.

/**
 * Check min() and max() over _key use correct index
 * Test uses value object cache
 */
public void testMinMaxQueryPlanOnKey() throws Exception {
    try (Ignite client = startGrid("client")) {
        IgniteCache<Integer, ValueObj> cache = client.cache(CACHE_NAME_2);
        QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_key), max(_key) from ValueObj"));
        List<List<?>> result = cursor.getAll();
        assertEquals(2, result.size());
        assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("_key_pk"));
        assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("direct lookup"));
    }
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 87 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteSqlQueryMinMaxTest method testSimpleMinMaxQueryPlanOnValue.

/**
 * Check min() and max() over _val uses correct index.
 * Test uses primitive cache
 */
public void testSimpleMinMaxQueryPlanOnValue() throws Exception {
    try (Ignite client = startGrid("client")) {
        IgniteCache<Integer, Integer> cache = client.cache(CACHE_NAME);
        QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_val), max(_val) from Integer"));
        List<List<?>> result = cursor.getAll();
        assertEquals(2, result.size());
        assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("_val_idx"));
        assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("direct lookup"));
    }
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 88 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class GridMarshallerAbstractTest method testMarshallingAnonymousClassInstance.

/**
 * Tests marshal anonymous class instance.
 *
 * @throws Exception If test failed.
 */
public void testMarshallingAnonymousClassInstance() throws Exception {
    final Ignite g = grid();
    GridMarshallerTestBean inBean = newTestBean(new IgniteClosure() {

        /**
         */
        private Iterable<ClusterNode> nodes = g.cluster().nodes();

        /**
         * {@inheritDoc}
         */
        @Override
        public Object apply(Object o) {
            return nodes;
        }
    });
    byte[] buf = marshal(inBean);
    GridMarshallerTestBean outBean = unmarshal(buf);
    assert inBean.getObjectField() != null;
    assert outBean.getObjectField() != null;
    assert IgniteClosure.class.isAssignableFrom(inBean.getObjectField().getClass());
    assert IgniteClosure.class.isAssignableFrom(outBean.getObjectField().getClass());
    assert inBean.getObjectField() != outBean.getObjectField();
    assert inBean != outBean;
    assert inBean.equals(outBean);
    outBean.checkNullResources();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClosure(org.apache.ignite.lang.IgniteClosure) Ignite(org.apache.ignite.Ignite)

Example 89 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteSqlQueryMinMaxTest method testJoinGroupMinMax.

/**
 * Check min() and max() over group with joins
 */
public void testJoinGroupMinMax() throws Exception {
    try (Ignite client = startGrid("client")) {
        IgniteCache<Integer, Integer> cache = client.cache(CACHE_NAME);
        IgniteCache<Integer, ValueObj> cache2 = client.cache(CACHE_NAME_2);
        int count = 1_000;
        int groupSize = 100;
        for (int idx = 0; idx < count; ++idx) {
            cache.put(idx, idx);
            cache2.put(idx, new ValueObj(count - idx - 1, groupSize));
        }
        // join a.key = b.key, collocated
        QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select b.groupVal, min(a._key), max(a._key), min(a._val), max(a._val), " + "min(b._key), max(b._key), min(b.idxVal), max(b.idxVal), min(b.nonIdxVal), max(b.nonIdxVal) " + "from \"intCache\".Integer a, \"valCache\".ValueObj b where a._key = b._key " + "group by b.groupVal order by b.groupVal"));
        List<List<?>> result = cursor.getAll();
        assertEquals(count / groupSize, result.size());
        for (int idx = 0; idx < result.size(); ++idx) {
            assertEquals(idx, result.get(idx).get(0));
            int min = idx * groupSize;
            int max = (idx + 1) * groupSize - 1;
            int revMin = count - max - 1;
            int revMax = count - min - 1;
            // min(a._key)
            assertEquals(revMin, result.get(idx).get(1));
            // max(a._key)
            assertEquals(revMax, result.get(idx).get(2));
            // min(a._val)
            assertEquals(revMin, result.get(idx).get(3));
            // max(a._val)
            assertEquals(revMax, result.get(idx).get(4));
            // min(b._key)
            assertEquals(revMin, result.get(idx).get(5));
            // max(b_key)
            assertEquals(revMax, result.get(idx).get(6));
            // min(b.idxVal)
            assertEquals(min, result.get(idx).get(7));
            // max(b.idxVal),
            assertEquals(max, result.get(idx).get(8));
            // min(b.nonIdxVal)
            assertEquals(min, result.get(idx).get(9));
            // max(b.nonIdxVal)
            assertEquals(max, result.get(idx).get(10));
        }
        // join a.key = b.val, non-collocated
        cursor = cache.query(new SqlFieldsQuery("select b.groupVal, min(a._key), max(a._key), min(a._val), max(a._val), " + "min(b._key), max(b._key), min(b.idxVal), max(b.idxVal), min(b.nonIdxVal), max(b.nonIdxVal) " + "from \"intCache\".Integer a, \"valCache\".ValueObj b where a._key = b.idxVal " + "group by b.groupVal order by b.groupVal").setDistributedJoins(true));
        result = cursor.getAll();
        assertEquals(count / groupSize, result.size());
        for (int idx = 0; idx < result.size(); ++idx) {
            assertEquals(idx, result.get(idx).get(0));
            int min = idx * groupSize;
            int max = (idx + 1) * groupSize - 1;
            int revMin = count - max - 1;
            int revMax = count - min - 1;
            // min(a._key)
            assertEquals(min, result.get(idx).get(1));
            // max(a._key)
            assertEquals(max, result.get(idx).get(2));
            // min(a._val)
            assertEquals(min, result.get(idx).get(3));
            // max(a._val)
            assertEquals(max, result.get(idx).get(4));
            // min(b._key)
            assertEquals(revMin, result.get(idx).get(5));
            // max(b_key)
            assertEquals(revMax, result.get(idx).get(6));
            // min(b.idxVal)
            assertEquals(min, result.get(idx).get(7));
            // max(b.idxVal),
            assertEquals(max, result.get(idx).get(8));
            // min(b.nonIdxVal)
            assertEquals(min, result.get(idx).get(9));
            // max(b.nonIdxVal)
            assertEquals(max, result.get(idx).get(10));
        }
    }
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 90 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteSqlQueryMinMaxTest method testSimpleMinMaxQueryPlanOnKey.

/**
 * Check min() and max() over _key uses correct index
 * Test uses primitive cache
 */
public void testSimpleMinMaxQueryPlanOnKey() throws Exception {
    try (Ignite client = startGrid("client")) {
        IgniteCache<Integer, Integer> cache = client.cache(CACHE_NAME);
        QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select min(_key), max(_key) from Integer"));
        List<List<?>> result = cursor.getAll();
        assertEquals(2, result.size());
        assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("_key_pk"));
        assertTrue(((String) result.get(0).get(0)).toLowerCase().contains("direct lookup"));
    }
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

Ignite (org.apache.ignite.Ignite)2007 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)358 CountDownLatch (java.util.concurrent.CountDownLatch)238 IgniteCache (org.apache.ignite.IgniteCache)234 IgniteException (org.apache.ignite.IgniteException)216 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)215 Transaction (org.apache.ignite.transactions.Transaction)194 ArrayList (java.util.ArrayList)177 ClusterNode (org.apache.ignite.cluster.ClusterNode)152 UUID (java.util.UUID)137 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)135 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)128 CacheException (javax.cache.CacheException)112 Event (org.apache.ignite.events.Event)112 HashMap (java.util.HashMap)105 List (java.util.List)89 IgniteEx (org.apache.ignite.internal.IgniteEx)85 Map (java.util.Map)84 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)81 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)78