Search in sources :

Example 6 with SqlFieldsQuery

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

the class JdbcUpdateStatementSelfTest method testExecute.

/**
     *
     */
public void testExecute() throws SQLException {
    conn.createStatement().execute("update Person set firstName = 'Jack' where " + "cast(substring(_key, 2, 1) as int) % 2 = 0");
    assertEquals(Arrays.asList(F.asList("John"), F.asList("Jack"), F.asList("Mike")), jcache(0).query(new SqlFieldsQuery("select firstName from Person order by _key")).getAll());
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 7 with SqlFieldsQuery

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

the class JdbcUpdateStatementSelfTest method testExecuteUpdate.

/**
     *
     */
public void testExecuteUpdate() throws SQLException {
    conn.createStatement().executeUpdate("update Person set firstName = 'Jack' where " + "cast(substring(_key, 2, 1) as int) % 2 = 0");
    assertEquals(Arrays.asList(F.asList("John"), F.asList("Jack"), F.asList("Mike")), jcache(0).query(new SqlFieldsQuery("select firstName from Person order by _key")).getAll());
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 8 with SqlFieldsQuery

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

the class JdbcThinDynamicIndexAbstractSelfTest method testCreateIndex.

/**
     * Test that after index creation index is used by queries.
     * @throws SQLException If failed.
     */
public void testCreateIndex() throws SQLException {
    assertSize(3);
    assertColumnValues(30, 20, 10);
    jdbcRun(CREATE_INDEX);
    // Test that local queries on all server nodes use new index.
    for (int i = 0; i < 3; i++) {
        List<List<?>> locRes = ignite(i).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("explain select id from " + "Person where id = 5").setLocal(true)).getAll();
        assertEquals(F.asList(Collections.singletonList("SELECT\n" + "    ID\n" + "FROM \"" + DEFAULT_CACHE_NAME + "\".PERSON\n" + "    /* \"" + DEFAULT_CACHE_NAME + "\".IDX: ID = 5 */\n" + "WHERE ID = 5")), locRes);
    }
    assertSize(3);
    assertColumnValues(30, 20, 10);
}
Also used : List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 9 with SqlFieldsQuery

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

the class JdbcThinDynamicIndexAbstractSelfTest method testDropIndex.

/**
     * Test that after index drop there are no attempts to use it, and data state remains intact.
     * @throws SQLException If failed.
     */
public void testDropIndex() throws SQLException {
    assertSize(3);
    jdbcRun(CREATE_INDEX);
    assertSize(3);
    jdbcRun(DROP_INDEX);
    // Test that no local queries on server nodes use new index.
    for (int i = 0; i < 3; i++) {
        List<List<?>> locRes = ignite(i).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("explain select id from " + "Person where id = 5").setLocal(true)).getAll();
        assertEquals(F.asList(Collections.singletonList("SELECT\n" + "    ID\n" + "FROM \"" + DEFAULT_CACHE_NAME + "\".PERSON\n" + "    /* \"" + DEFAULT_CACHE_NAME + "\".PERSON.__SCAN_ */\n" + "WHERE ID = 5")), locRes);
    }
    assertSize(3);
}
Also used : List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 10 with SqlFieldsQuery

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

the class JdbcThinUpdateStatementSelfTest method testExecute.

/**
     * @throws SQLException If failed.
     */
public void testExecute() throws SQLException {
    conn.createStatement().execute("update Person set firstName = 'Jack' where " + "cast(substring(_key, 2, 1) as int) % 2 = 0");
    assertEquals(Arrays.asList(F.asList("John"), F.asList("Jack"), F.asList("Mike")), jcache(0).query(new SqlFieldsQuery("select firstName from Person order by _key")).getAll());
}
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