Search in sources :

Example 26 with SqlFieldsQuery

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

the class CacheAbstractQueryMetricsSelfTest method testSqlFieldsCrossCacheQueryFailedMetrics.

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

Example 27 with SqlFieldsQuery

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

the class IgniteCacheDistributedJoinCustomAffinityMapper method testJoinCustomAffinityMapper.

/**
     * @throws Exception If failed.
     */
public void testJoinCustomAffinityMapper() throws Exception {
    Ignite ignite = ignite(0);
    IgniteCache<Object, Object> cache = ignite.cache(PERSON_CACHE);
    checkQueryFails(cache, "select o._key k1, p._key k2 " + "from \"org\".Organization o, \"personCustomAff\".Person p where o._key=p.orgId", false);
    checkQueryFails(cache, "select o._key k1, p._key k2 " + "from \"personCustomAff\".Person p, \"org\".Organization o where o._key=p.orgId", false);
    {
        // Check regular query does not fail.
        SqlFieldsQuery qry = new SqlFieldsQuery("select o._key k1, p._key k2 " + "from \"org\".Organization o, \"personCustomAff\".Person p where o._key=p.orgId");
        cache.query(qry).getAll();
    }
    {
        // Should not check affinity for replicated cache.
        SqlFieldsQuery qry = new SqlFieldsQuery("select o1._key k1, p._key k2, o2._key k3 " + "from \"org\".Organization o1, \"person\".Person p, \"orgReplCustomAff\".Organization o2 where " + "o1._key=p.orgId and o2._key=p.orgId");
        cache.query(qry).getAll();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 28 with SqlFieldsQuery

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

the class IgniteCacheDistributedJoinNoIndexTest method checkNoIndexError.

/**
     * @param cache Cache.
     * @param sql SQL.
     */
private void checkNoIndexError(final IgniteCache<Object, Object> cache, final String sql) {
    Throwable err = GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            SqlFieldsQuery qry = new SqlFieldsQuery(sql);
            qry.setDistributedJoins(true);
            cache.query(qry).getAll();
            return null;
        }
    }, CacheException.class, null);
    log.info("Error: " + err.getMessage());
    assertTrue("Unexpected error message: " + err.getMessage(), err.getMessage().contains("join condition does not use index"));
}
Also used : CacheException(javax.cache.CacheException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 29 with SqlFieldsQuery

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

the class IgniteCacheDeleteSqlQuerySelfTest method testDeleteSimpleWithoutKeepBinary.

/**
     * In binary mode, this test checks that inner forcing of keepBinary works - without it, EntryProcessors
     * inside DML engine would compare binary and non-binary objects with the same keys and thus fail.
     */
public void testDeleteSimpleWithoutKeepBinary() {
    IgniteCache p = ignite(0).cache("S2P");
    QueryCursor<List<?>> c = p.query(new SqlFieldsQuery("delete from Person p where length(p._key) = 2 " + "or p.secondName like '%ite'"));
    c.iterator();
    c = p.query(new SqlFieldsQuery("select _key, _val, * from Person order by id"));
    List<List<?>> leftovers = c.getAll();
    assertEquals(2, leftovers.size());
    assertEqualsCollections(Arrays.asList("SecondKey", new Person(2, "Joe", "Black"), 2, "Joe", "Black"), leftovers.get(0));
    assertEqualsCollections(Arrays.asList("f0u4thk3y", new Person(4, "Jane", "Silver"), 4, "Jane", "Silver"), leftovers.get(1));
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 30 with SqlFieldsQuery

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

the class IgniteCacheDeleteSqlQuerySelfTest method testDeleteSingle.

/**
     *
     */
public void testDeleteSingle() {
    IgniteCache p = cache();
    QueryCursor<List<?>> c = p.query(new SqlFieldsQuery("delete from Person where _key = ?").setArgs("FirstKey"));
    c.iterator();
    c = p.query(new SqlFieldsQuery("select _key, _val, * from Person order by id, _key"));
    List<List<?>> leftovers = c.getAll();
    assertEquals(3, leftovers.size());
    assertEqualsCollections(Arrays.asList("SecondKey", createPerson(2, "Joe", "Black"), 2, "Joe", "Black"), leftovers.get(0));
    assertEqualsCollections(Arrays.asList("k3", createPerson(3, "Sylvia", "Green"), 3, "Sylvia", "Green"), leftovers.get(1));
    assertEqualsCollections(Arrays.asList("f0u4thk3y", createPerson(4, "Jane", "Silver"), 4, "Jane", "Silver"), leftovers.get(2));
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) List(java.util.List) 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