Search in sources :

Example 31 with SqlFieldsQuery

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

the class IgniteCacheReplicatedFieldsQueryJoinNoPrimaryPartitionsSelfTest method testJoinNonCollocated.

/**
 * Test non-colocated join.
 *
 * @throws Exception If failed.
 */
public void testJoinNonCollocated() throws Exception {
    SqlFieldsQuery qry = new SqlFieldsQuery("SELECT COUNT(*) FROM PartValue p, RepValue r WHERE p.repId=r.id");
    long cnt = (Long) grid(NODE_CLI).cache(CACHE_PARTITIONED).query(qry).getAll().get(0).get(0);
    assertEquals(PART_CNT, cnt);
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 32 with SqlFieldsQuery

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

the class IgniteCacheDistributedJoinTest method checkSameResult.

/**
 * @param s Statement.
 * @param c Cache.
 * @param qry Query.
 * @throws SQLException If failed.
 */
private <Z extends X> void checkSameResult(Statement s, IgniteCache<Integer, Z> c, String qry) throws SQLException {
    s.executeUpdate("SET SCHEMA " + c.getName());
    try (ResultSet rs1 = s.executeQuery(qry);
        QueryCursor<List<?>> rs2 = c.query(new SqlFieldsQuery(qry).setDistributedJoins(true))) {
        Iterator<List<?>> iter = rs2.iterator();
        for (; ; ) {
            if (!rs1.next()) {
                assertFalse(iter.hasNext());
                return;
            }
            assertTrue(iter.hasNext());
            List<?> row = iter.next();
            for (int i = 0; i < row.size(); i++) assertEquals(rs1.getLong(i + 1), row.get(i));
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 33 with SqlFieldsQuery

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

the class IgniteSqlSegmentedIndexSelfTest method checkLocalQueryWithSegmentedIndex.

/**
 * Test local query.
 *
 * @throws Exception If failed.
 */
public void checkLocalQueryWithSegmentedIndex() throws Exception {
    for (int i = 0; i < nodesCount(); i++) {
        final Ignite node = ignite(i);
        IgniteCache<Integer, Person> c1 = node.cache(PERSON_CAHE_NAME);
        IgniteCache<Integer, Organization> c2 = node.cache(ORG_CACHE_NAME);
        Set<Integer> locOrgIds = new HashSet<>();
        for (Cache.Entry<Integer, Organization> e : c2.localEntries()) locOrgIds.add(e.getKey());
        long expPersons = 0;
        for (Cache.Entry<Integer, Person> e : c1.localEntries()) {
            final Integer orgId = e.getValue().orgId;
            if (locOrgIds.contains(orgId))
                expPersons++;
        }
        String select0 = "select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
        List<List<?>> res = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll();
        assertEquals(expPersons, res.size());
    }
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List) HashSet(java.util.HashSet) IgniteCache(org.apache.ignite.IgniteCache) Cache(javax.cache.Cache)

Example 34 with SqlFieldsQuery

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

the class IgniteSqlSegmentedIndexSelfTest method testSegmentedIndexWithEvictionPolicy.

/**
 * Run tests on single-node grid
 *
 * @throws Exception If failed.
 */
public void testSegmentedIndexWithEvictionPolicy() throws Exception {
    final IgniteCache<Object, Object> cache = ignite(0).createCache(cacheConfig(ORG_CACHE_NAME, true, Integer.class, Organization.class).setEvictionPolicy(new FifoEvictionPolicy(10)).setOnheapCacheEnabled(true));
    final long SIZE = 20;
    for (int i = 0; i < SIZE; i++) cache.put(i, new Organization("org-" + i));
    String select0 = "select name from \"org\".Organization";
    List<List<?>> res = cache.query(new SqlFieldsQuery(select0)).getAll();
    assertEquals(SIZE, res.size());
}
Also used : List(java.util.List) FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 35 with SqlFieldsQuery

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

the class IgniteSqlSegmentedIndexSelfTest method checkLocalSizeQueryWithSegmentedIndex.

/**
 * Verifies that local <code>select count(*)</code> query returns a correct result.
 *
 * @throws Exception If failed.
 */
public void checkLocalSizeQueryWithSegmentedIndex() throws Exception {
    for (int i = 0; i < nodesCount(); i++) {
        final Ignite node = ignite(i);
        IgniteCache<Integer, Person> c1 = node.cache(PERSON_CAHE_NAME);
        IgniteCache<Integer, Organization> c2 = node.cache(ORG_CACHE_NAME);
        Set<Integer> locOrgIds = new HashSet<>();
        for (Cache.Entry<Integer, Organization> e : c2.localEntries()) locOrgIds.add(e.getKey());
        int expPersons = 0;
        for (Cache.Entry<Integer, Person> e : c1.localEntries()) {
            final Integer orgId = e.getValue().orgId;
            if (locOrgIds.contains(orgId))
                expPersons++;
        }
        String select0 = "select count(*) from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
        List<List<?>> res = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll();
        assertEquals((long) expPersons, res.get(0).get(0));
    }
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List) HashSet(java.util.HashSet) IgniteCache(org.apache.ignite.IgniteCache) Cache(javax.cache.Cache)

Aggregations

SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)272 List (java.util.List)171 ArrayList (java.util.ArrayList)81 Ignite (org.apache.ignite.Ignite)43 IgniteCache (org.apache.ignite.IgniteCache)36 CacheException (javax.cache.CacheException)28 SqlQuery (org.apache.ignite.cache.query.SqlQuery)21 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)19 Cache (javax.cache.Cache)17 IgniteException (org.apache.ignite.IgniteException)16 IgniteEx (org.apache.ignite.internal.IgniteEx)15 Random (java.util.Random)11 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)10 GridRandom (org.apache.ignite.internal.util.GridRandom)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 BinaryObject (org.apache.ignite.binary.BinaryObject)8 QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)8