Search in sources :

Example 16 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 17 with SqlFieldsQuery

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

the class IgniteCacheInsertSqlQuerySelfTest method testInsertFromSubquery.

/**
     *
     */
public void testInsertFromSubquery() {
    IgniteCache p = ignite(0).cache("S2P").withKeepBinary();
    p.query(new SqlFieldsQuery("insert into String (_key, _val) values ('s', ?), " + "('a', ?)").setArgs("Sergi", "Alex").setLocal(true));
    assertEquals("Sergi", p.get("s"));
    assertEquals("Alex", p.get("a"));
    p.query(new SqlFieldsQuery("insert into Person(_key, id, firstName) " + "(select substring(lower(_val), 0, 2), cast(length(_val) as int), _val from String)"));
    assertEquals(createPerson(5, "Sergi"), p.get("se"));
    assertEquals(createPerson(4, "Alex"), p.get("al"));
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 18 with SqlFieldsQuery

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

the class IgniteCacheInsertSqlQuerySelfTest method testUuidHandling.

/**
     *
     */
public void testUuidHandling() {
    IgniteCache<UUID, Integer> p = ignite(0).cache("U2I");
    UUID id = UUID.randomUUID();
    p.query(new SqlFieldsQuery("insert into Integer(_key, _val) values (?, ?)").setArgs(id, 1));
    assertEquals(1, (int) p.get(id));
}
Also used : UUID(java.util.UUID) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 19 with SqlFieldsQuery

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

the class IgniteCacheInsertSqlQuerySelfTest method testNestedFieldsHandling.

/**
     *
     */
public void testNestedFieldsHandling() {
    IgniteCache<Integer, AllTypes> p = ignite(0).cache("I2AT");
    p.query(new SqlFieldsQuery("insert into AllTypes(_key, innerTypeCol, arrListCol, _val, innerStrCol) values (1, ?, ?, ?, 'sss')").setArgs(new AllTypes.InnerType(50L), new ArrayList<>(Arrays.asList(3L, 2L, 1L)), new AllTypes(1L)));
    AllTypes res = p.get(1);
    AllTypes.InnerType resInner = new AllTypes.InnerType(50L);
    resInner.innerStrCol = "sss";
    resInner.arrListCol = new ArrayList<>(Arrays.asList(3L, 2L, 1L));
    assertEquals(resInner, res.innerTypeCol);
}
Also used : ArrayList(java.util.ArrayList) AllTypes(org.apache.ignite.internal.processors.cache.IgniteCacheUpdateSqlQuerySelfTest.AllTypes) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 20 with SqlFieldsQuery

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

the class CacheAbstractQueryMetricsSelfTest method testSqlFieldsQueryMetrics.

/**
     * Test metrics for SQL fields queries.
     *
     * @throws Exception In case of error.
     */
public void testSqlFieldsQueryMetrics() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
    SqlFieldsQuery qry = new SqlFieldsQuery("select * from String");
    checkQueryMetrics(cache, qry);
}
Also used : 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