Search in sources :

Example 81 with SqlFieldsQuery

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

the class IgniteSqlRoutingTest method testUnicastQueryAffinityKeyTypeConversionConstant.

/**
 */
@Test
public void testUnicastQueryAffinityKeyTypeConversionConstant() throws Exception {
    IgniteCache<CallKey, Call> cache = grid(NODE_CLIENT).cache(CACHE_CALL);
    // Use string within expression against integer key
    List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select id, name, duration from Call where personId='100' order by id"), 1);
    assertEquals(2, result.size());
    checkResultsRow(result, 0, 1, "caller1", 100);
    checkResultsRow(result, 1, 2, "caller2", 200);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 82 with SqlFieldsQuery

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

the class IgniteSqlRoutingTest method runQueryEnsureUnicast.

/**
 * Run query and check that only one node did generate 'query executed' event for it.
 */
private List<List<?>> runQueryEnsureUnicast(IgniteCache<?, ?> cache, SqlFieldsQuery qry, int nodeCnt) throws Exception {
    try (EventCounter evtCounter = new EventCounter(nodeCnt)) {
        List<List<?>> result = cache.query(qry).getAll();
        // do broadcast 'marker' query to ensure that we received all events from previous qry
        cache.query(new SqlFieldsQuery(MessageFormat.format(FINAL_QRY, cache.getName())).setArgs(FINAL_QRY_PARAM)).getAll();
        // wait for all events from 'marker' query
        evtCounter.await();
        // return result set of first query
        return result;
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 83 with SqlFieldsQuery

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

the class IgniteSqlRoutingTest method testUnicastQueryKeyTypeConversionConstant.

/**
 */
@Test
public void testUnicastQueryKeyTypeConversionConstant() throws Exception {
    IgniteCache<Integer, Person> cache = grid(NODE_CLIENT).cache(CACHE_PERSON);
    // Use string within expression against integer key
    List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select name, age from Person where _key = '5'"), 1);
    Person person = cache.get(5);
    assertEquals(1, result.size());
    assertEquals(person.name, result.get(0).get(0));
    assertEquals(person.age, result.get(0).get(1));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 84 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.
 */
@SuppressWarnings("deprecation")
@Test
public void testSegmentedIndexWithEvictionPolicy() {
    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) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 85 with SqlFieldsQuery

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

the class IgniteSqlSegmentedIndexSelfTest method checkLocalQueryWithSegmentedIndex.

/**
 * Test local query.
 */
public void checkLocalQueryWithSegmentedIndex() {
    for (int i = 0; i < nodesCount(); i++) {
        final Ignite node = ignite(i);
        IgniteCache<PersonKey, 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<PersonKey, Person> e : c1.localEntries()) {
            final Integer orgId = e.getKey().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)

Aggregations

SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)679 Test (org.junit.Test)388 List (java.util.List)373 Ignite (org.apache.ignite.Ignite)170 ArrayList (java.util.ArrayList)136 IgniteCache (org.apache.ignite.IgniteCache)123 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)115 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)94 IgniteEx (org.apache.ignite.internal.IgniteEx)90 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)83 Transaction (org.apache.ignite.transactions.Transaction)80 CacheException (javax.cache.CacheException)67 Random (java.util.Random)55 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)53 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)52 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)45 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)41 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)32 HashMap (java.util.HashMap)31 Cache (javax.cache.Cache)31