Search in sources :

Example 26 with SqlQuery

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

the class IgniteCacheReplicatedQuerySelfTest method testClientOnlyNode.

/**
     * @throws Exception If failed.
     */
public void testClientOnlyNode() throws Exception {
    try {
        Ignite g = startGrid("client");
        IgniteCache<Integer, Integer> c = jcache(g, Integer.class, Integer.class);
        for (int i = 0; i < 10; i++) c.put(i, i);
        // Client cache should be empty.
        assertEquals(0, c.localSize());
        Collection<Cache.Entry<Integer, Integer>> res = c.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= 5 order by _key")).getAll();
        assertEquals(5, res.size());
        int i = 5;
        for (Cache.Entry<Integer, Integer> e : res) {
            assertEquals(i, e.getKey().intValue());
            assertEquals(i, e.getValue().intValue());
            i++;
        }
    } finally {
        stopGrid("client");
    }
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) Ignite(org.apache.ignite.Ignite) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 27 with SqlQuery

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

the class DynamicIndexAbstractSelfTest method assertSqlCompositeData.

/**
     * Assert SQL simple data state.
     *
     * @param node Node.
     * @param sql SQL query.
     * @param expSize Expected size.
     */
protected static void assertSqlCompositeData(Ignite node, String sql, int expSize) {
    SqlQuery qry = new SqlQuery(typeName(ValueClass.class), sql).setArgs(SQL_ARG_1, SQL_ARG_2);
    List<Cache.Entry<BinaryObject, BinaryObject>> res = node.cache(CACHE_NAME).withKeepBinary().query(qry).getAll();
    Set<Long> ids = new HashSet<>();
    for (Cache.Entry<BinaryObject, BinaryObject> entry : res) {
        long id = entry.getKey().field(FIELD_KEY);
        long field1 = entry.getValue().field(FIELD_NAME_1_ESCAPED);
        long field2 = entry.getValue().field(FIELD_NAME_2_ESCAPED);
        assertTrue(field1 >= SQL_ARG_2);
        assertEquals(id, field1);
        assertEquals(id, field2);
        assertTrue(ids.add(id));
    }
    assertEquals("Size mismatch [exp=" + expSize + ", actual=" + res.size() + ", ids=" + ids + ']', expSize, res.size());
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) BinaryObject(org.apache.ignite.binary.BinaryObject) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 28 with SqlQuery

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

the class IgniteSqlMergeQueryBenchmark method executeQuery.

/**
     * @param minSalary Min salary.
     * @param maxSalary Max salary.
     * @return Query result.
     * @throws Exception If failed.
     */
private Collection<Cache.Entry<Integer, Object>> executeQuery(double minSalary, double maxSalary) throws Exception {
    SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?");
    qry.setArgs(minSalary, maxSalary);
    return cache.query(qry).getAll();
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery)

Example 29 with SqlQuery

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

the class IgniteSqlQueryPutSeparatedBenchmark method executeQuery.

/**
     * @param minSalary Min salary.
     * @param maxSalary Max salary.
     * @return Query result.
     * @throws Exception If failed.
     */
private Collection<Cache.Entry<Integer, Object>> executeQuery(double minSalary, double maxSalary) throws Exception {
    SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?");
    qry.setArgs(minSalary, maxSalary);
    return cache.query(qry).getAll();
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery)

Example 30 with SqlQuery

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

the class IgniteSqlQueryBenchmark method executeQuery.

/**
     * @param minSalary Min salary.
     * @param maxSalary Max salary.
     * @return Query result.
     * @throws Exception If failed.
     */
private Collection<Cache.Entry<Integer, Object>> executeQuery(double minSalary, double maxSalary) throws Exception {
    SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?");
    qry.setArgs(minSalary, maxSalary);
    return cache.query(qry).getAll();
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery)

Aggregations

SqlQuery (org.apache.ignite.cache.query.SqlQuery)57 Cache (javax.cache.Cache)20 IgniteCache (org.apache.ignite.IgniteCache)20 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)18 Ignite (org.apache.ignite.Ignite)17 List (java.util.List)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 CAX (org.apache.ignite.internal.util.typedef.CAX)9 ArrayList (java.util.ArrayList)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 BinaryObject (org.apache.ignite.binary.BinaryObject)7 CacheException (javax.cache.CacheException)6 Collection (java.util.Collection)4 Random (java.util.Random)4 QueryCursor (org.apache.ignite.cache.query.QueryCursor)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 UUID (java.util.UUID)3