Java Code Examples for org.apache.ignite.cache.query.SqlFieldsQuery

The following examples show how to use org.apache.ignite.cache.query.SqlFieldsQuery. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Tests updating of all Date and Time fields.
 * <p>
 * Trim precision of {@link LocalDateTime} to milliseconds.
 * Nanosecond precision test -- {@link #testUpdateAllFields}.
 */
@Test
public void testUpdateAllFieldsMillisTimePrecision() {
    EntityWithDateTimeFields expEntity = new EntityWithDateTimeFields(entity);

    expEntity.setLocalTime(expEntity.getLocalTime().plusHours(1).withNano(0).plus(123, MILLIS));
    expEntity.setLocalDate(expEntity.getLocalDate().plusDays(1));
    expEntity.setLocalDateTime(LocalDateTime.of(expEntity.getLocalDate(), expEntity.getLocalTime()));

    SqlFieldsQuery qry = new SqlFieldsQuery(
        "update EntityWithDateTimeFields set locTime = ?, locDate = ?, locDateTime = ? where id = ?"
    ).setArgs(expEntity.getLocalTime(), expEntity.getLocalDate(), expEntity.getLocalDateTime(), entity.getId());

    List<List<?>> qryResults = cache.query(qry).getAll();

    assertEquals(1, qryResults.size());
    assertEquals(1L, qryResults.get(0).get(0));
    assertEquals(expEntity, cache.get(expEntity.getId()));
}
 
Example 2
/**
 * It should not matter what cache mode does entry cache use, if there is no join
 */
@Test
public void testCrossCacheModeQuery() throws Exception {
    Ignite ignite = startGrid();

    ignite.cache(LOCAL_CACHE_NAME).put(1, LOCAL_CACHE_NAME);
    ignite.cache(REPLICATED_CACHE_NAME).put(1, REPLICATED_CACHE_NAME);
    ignite.cache(PARTITIONED_CACHE_NAME).put(1, PARTITIONED_CACHE_NAME);

    final List<String> cacheNamesList = F.asList(LOCAL_CACHE_NAME, REPLICATED_CACHE_NAME, PARTITIONED_CACHE_NAME);

    for (String entryCacheName: cacheNamesList) {
        for (String qryCacheName: cacheNamesList) {
            if (entryCacheName.equals(qryCacheName))
                continue;

            QueryCursor<List<?>> cursor = ignite.cache(entryCacheName).query(
                new SqlFieldsQuery("SELECT _VAL FROM \"" + qryCacheName + "\".String"));

            assertEquals(qryCacheName, (String)cursor.getAll().get(0).get(0));
        }
    }
}
 
Example 3
/**
 * Example for SQL-based fields queries that return only required fields instead of whole key-value pairs.
 */
private static void sqlFieldsQueryWithJoin() {
    IgniteCache<?, ?> cache = Ignition.ignite().cache(EMPLOYEE_CACHE_NAME);

    // Create query to get names of all employees.
    SqlFieldsQuery qry = new SqlFieldsQuery(
        "select e.ename, d.dname " +
            "from Employee e, \"" + DEPARTMENT_CACHE_NAME + "\".Department d " +
            "where e.deptno = d.deptno");

    // Execute query to get collection of rows. In this particular
    // case each row will have one element with full name of an employees.
    Collection<List<?>> res = cache.query(qry).getAll();

    // Print persons' names and departments' names.
    logDecorated("==Names of all employees and departments they belong to (SQL join)==", res);
}
 
Example 4
/**
 * @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"));
}
 
Example 5
/**
 * Example for SQL-based fields queries that return only required fields instead of whole key-value pairs.
 */
private static void groupByQuery() {
    IgniteCache<?, ?> cache = Ignition.ignite().cache(EMPLOYEE_CACHE_NAME);

    // Create query to get salary averages grouped by department name.
    // We don't need to perform any extra manual steps here, because
    // Employee data is colocated based on department IDs.
    SqlFieldsQuery qry = new SqlFieldsQuery(
        "select avg(e.sal), d.dname " +
            "from Employee e, \"" + DEPARTMENT_CACHE_NAME + "\".Department d " +
            "where e.deptno = d.deptno " +
            "group by d.dname " +
            "having avg(e.sal) > ?");

    // Execute query to get collection of rows.
    logDecorated("==Average salaries per Department (group-by query)==", cache.query(qry.setArgs(500)).getAll());
}
 
Example 6
/**
 * @throws Exception On error.
 */
@Test
public void testPutAll() throws Exception {
    IgniteEx ign = startGrid(0);

    IgniteCache<Object, Object> cache = ign.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
        .setAtomicityMode(atomicity())
        .setIndexedTypes(Integer.class, Integer.class));

    final Map<Integer, Integer> batch = new HashMap<>();

    for (int i = 0; i < KEYS; ++i)
        batch.put(i, i);

    Thread t = new Thread(() -> {
        cache.putAll(batch);
    });

    t.start();
    t.interrupt();
    t.join();

    assertEquals(cache.size(), cache.query(new SqlFieldsQuery("select * from Integer")).getAll().size());
}
 
Example 7
Source Project: ignite   Source File: H2IndexingAbstractGeoSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testPrimitiveGeometry() throws Exception {
    IgniteCache<Long, Geometry> cache = createCache("geom", true, Long.class, Geometry.class);

    try {
        WKTReader r = new WKTReader();

        for (long i = 0; i < 100; i++)
            cache.put(i, r.read("POINT(" + i + " " + i + ")"));

        String plan = cache.query(new SqlFieldsQuery("explain select _key from Geometry where _val && ?")
            .setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))")).setLocal(true))
            .getAll().get(0).get(0).toString().toLowerCase();

        assertTrue("__ explain: " + plan, plan.contains("_val_idx"));
    }
    finally {
        cache.destroy();
    }
}
 
Example 8
Source Project: ignite   Source File: QueryParserResult.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param qryDesc Query descriptor.
 * @param qryParams Query parameters.
 * @param remainingQry Remaining query.
 * @param paramsMeta metadata info about positional parameters of current parsed query (not includes remainingSql).
 * @param select Select.
 * @param dml DML.
 * @param cmd Command.
 */
public QueryParserResult(
    QueryDescriptor qryDesc,
    QueryParameters qryParams,
    SqlFieldsQuery remainingQry,
    @NotNull List<JdbcParameterMeta> paramsMeta,
    @Nullable QueryParserResultSelect select,
    @Nullable QueryParserResultDml dml,
    @Nullable QueryParserResultCommand cmd
) {
    assert paramsMeta != null;

    this.qryDesc = qryDesc;
    this.qryParams = qryParams;
    this.remainingQry = remainingQry;
    this.paramsMeta = paramsMeta;
    this.select = select;
    this.dml = dml;
    this.cmd = cmd;
}
 
Example 9
Source Project: ignite   Source File: GridQueryProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Query SQL fields.
 *
 * @param cctx Cache context.
 * @param qry Query.
 * @param cliCtx Client context.
 * @param keepBinary Keep binary flag.
 * @param failOnMultipleStmts If {@code true} the method must throws exception when query contains
 *      more then one SQL statement.
 * @param cancel Hook for query cancellation.
 * @return Cursor.
 */
public List<FieldsQueryCursor<List<?>>> querySqlFields(
    @Nullable final GridCacheContext<?, ?> cctx,
    final SqlFieldsQuery qry,
    final SqlClientContext cliCtx,
    final boolean keepBinary,
    final boolean failOnMultipleStmts,
    @Nullable final GridQueryCancel cancel
) {
    return querySqlFields(
        cctx,
        qry,
        cliCtx,
        keepBinary,
        failOnMultipleStmts,
        GridCacheQueryType.SQL_FIELDS,
        cancel
    );
}
 
Example 10
Source Project: ignite   Source File: IgniteSqlGroupConcatCollocatedTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 */
@Test
public void testGroupConcatWithDistinct() {
    IgniteCache c = ignite(CLIENT).cache(CACHE_NAME);

    HashMap<Integer, String> exp = new HashMap<>();

    exp.put(1, "A");
    exp.put(2, "B,C");
    exp.put(3, "D,E,F");
    exp.put(4, "G,H,I,J");
    exp.put(5, "K,L,M,N,O");
    exp.put(6, "P,Q,R,S,T,U");

    List<List<Object>> res = c.query(
        new SqlFieldsQuery("select grp, GROUP_CONCAT(DISTINCT str0 ORDER BY str0) from Value group by grp")
            .setCollocated(true)).getAll();

    HashMap<Integer, String> resMap = resultMap(res);

    assertEquals(exp, resMap);
}
 
Example 11
Source Project: ignite   Source File: IgniteSqlKeyValueFieldsTest.java    License: Apache License 2.0 6 votes vote down vote up
/** Check automatic addition of index for keyFieldName column */
@Test
public void testAutoKeyFieldIndex() throws Exception {
    IgniteEx client = grid(NODE_CLIENT);
    IgniteCache<Integer, Person> cache = client.cache(CACHE_PERSON);

    QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select * from Person where id = 1"));
    List<List<?>> results = cursor.getAll();
    assertEquals(1, results.size());
    assertTrue(((String)results.get(0).get(0)).contains("\"_key_PK_proxy\""));

    cursor = cache.query(new SqlFieldsQuery("explain select * from Person where _key = 1"));
    results = cursor.getAll();
    assertEquals(1, results.size());
    assertTrue(((String)results.get(0).get(0)).contains("\"_key_PK\""));
}
 
Example 12
Source Project: ignite   Source File: CacheQueryNewClientSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testQueryFromNewClientCustomSchemaName() throws Exception {
    Ignite srv = startGrid("server");

    IgniteCache<Integer, Integer> cache1 = srv.createCache(new CacheConfiguration<Integer, Integer>().
        setName("cache1").setSqlSchema("cache1_sql").setIndexedTypes(Integer.class, Integer.class));
    IgniteCache<Integer, Integer> cache2 = srv.createCache(new CacheConfiguration<Integer, Integer>().
        setName("cache2").setSqlSchema("cache2_sql").setIndexedTypes(Integer.class, Integer.class));

    for (int i = 0; i < 10; i++) {
        cache1.put(i, i);
        cache2.put(i, i);
    }

    Ignite client = startClientGrid("client");

    IgniteCache<Integer, Integer> cache = client.cache("cache1");

    List<List<?>> res = cache.query(new SqlFieldsQuery(
        "select i1._val, i2._val from Integer i1 cross join cache2_sql.Integer i2")).getAll();

    assertEquals(100, res.size());
}
 
Example 13
Source Project: ignite   Source File: StaticCacheDdlTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param ignite Ignite instance.
 * @param fieldName Field name to check.
 * @param shouldExist Should exist flag.
 */
private void checkField(Ignite ignite, String cacheName, String fieldName, boolean shouldExist) {
    SqlFieldsQuery q = new SqlFieldsQuery(
        "SELECT * FROM " + cacheName + "." + TABLE_NAME + " LIMIT 1 OFFSET 0" );

    boolean exists = false;

    try (FieldsQueryCursor<List<?>> cursor = ignite.cache(cacheName).query(q)) {
        consume(cursor);

        for (int i = 0, cols = cursor.getColumnsCount(); i < cols; i++) {
            if (cursor.getFieldName(i).equals(fieldName.toUpperCase())) {
                exists = true;

                break;
            }
        }
    }

    Assert.assertEquals("Check field (" + fieldName + ") exists", shouldExist, exists);
}
 
Example 14
Source Project: ignite   Source File: FunctionalQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 * @param minId Minimal ID.
 * @param pageSize Page size.
 * @param expSize The size of the expected results.
 * @param exp Expected results.
 * @param lazy Lazy mode flag.
 */
private void checkSqlFieldsQuery(ClientCache<Integer, Person> cache, int minId, int pageSize, int expSize,
    Map<Integer, Person> exp, boolean lazy) {
    SqlFieldsQuery qry = new SqlFieldsQuery("select id, name from Person where id >= ?")
        .setArgs(minId)
        .setPageSize(pageSize)
        .setLazy(lazy);

    try (QueryCursor<List<?>> cur = cache.query(qry)) {
        List<List<?>> res = cur.getAll();

        assertEquals(expSize, res.size());

        Map<Integer, Person> act = res.stream().collect(Collectors.toMap(
            r -> Integer.parseInt(r.get(0).toString()),
            r -> new Person(Integer.parseInt(r.get(0).toString()), r.get(1).toString())
        ));

        assertEquals(exp, act);
    }
}
 
Example 15
Source Project: ignite   Source File: IgniteCacheAbstractQuerySelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testFieldsQueryMetadata() throws Exception {
    IgniteCache<UUID, Person> cache = jcache(UUID.class, Person.class);

    for (int i = 0; i < 100; i++)
        cache.put(UUID.randomUUID(), new Person("name-" + i, (i + 1) * 100));

    QueryCursor<List<?>> cur = cache.query(new SqlFieldsQuery("select name, salary from Person where name like ?")
        .setArgs("name-"));

    assertTrue(cur instanceof QueryCursorEx);

    QueryCursorEx<List<?>> curEx = (QueryCursorEx<List<?>>)cur;

    List<GridQueryFieldMetadata> meta = curEx.fieldsMeta();

    assertNotNull(meta);
    assertEquals(2, meta.size());
}
 
Example 16
Source Project: ignite   Source File: KillQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check that local query can be canceled either using async or non-async method. Local query is performed using
 * cache.query() API with "local" property "true".
 */
@Test
public void testCancelLocalQueryNative() throws Exception {
    IgniteInternalFuture cancelRes = cancel(1, asyncCancel);

    GridTestUtils.assertThrowsAnyCause(log, () -> {
        ignite.cache(DEFAULT_CACHE_NAME).query(
            new SqlFieldsQuery("select * from Integer where _key in " +
                "(select _key from Integer where awaitLatchCancelled() = 0) and shouldNotBeCalledMoreThan(128)")
                .setLocal(true)
                .setLazy(false)
        ).getAll();

        return null;
    }, QueryCancelledException.class, "The query was cancelled while executing.");

    // Ensures that there were no exceptions within async cancellation process.
    cancelRes.get(CHECK_RESULT_TIMEOUT);
}
 
Example 17
Source Project: ignite   Source File: JdbcThinStreamingAbstractSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public List<FieldsQueryCursor<List<?>>> querySqlFields(
    String schemaName,
    SqlFieldsQuery qry,
    @Nullable SqlClientContext cliCtx,
    boolean keepBinary,
    boolean failOnMultipleStmts,
    GridQueryCancel cancel
) {
    IndexingWithContext.cliCtx = cliCtx;

    return super.querySqlFields(
        schemaName,
        qry,
        cliCtx,
        keepBinary,
        failOnMultipleStmts,
        cancel
    );
}
 
Example 18
Source Project: ignite   Source File: IgniteSqlSplitterSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check results of aggregate functions if no rows are selected.
 *
 * @throws Exception If failed,
 */
@Test
public void testEmptyCacheAggregates() throws Exception {
    final String cacheName = "ints";

    IgniteCache<Integer, Value> cache = ignite(0).getOrCreateCache(cacheConfig(cacheName, true,
        Integer.class, Value.class));

    try (QueryCursor<List<?>> qry = cache.query(new SqlFieldsQuery(
        "SELECT count(fst), sum(snd), avg(snd), min(snd), max(snd) FROM Value"))) {
        List<List<?>> result = qry.getAll();

        assertEquals(1, result.size());

        List<?> row = result.get(0);

        assertEquals("count", 0L, ((Number)row.get(0)).longValue());
        assertEquals("sum", null, row.get(1));
        assertEquals("avg", null, row.get(2));
        assertEquals("min", null, row.get(3));
        assertEquals("max", null, row.get(4));
    }
    finally {
        cache.destroy();
    }
}
 
Example 19
Source Project: ignite   Source File: IgniteSqlSplitterSelfTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache.
 * @param enforceJoinOrder Enforce join order flag.
 * @param expBatchedJoins Expected batched joins count.
 * @param sql Query.
 * @param expText Expected text to find in plan.
 */
private void checkQueryPlan(IgniteCache<Object, Object> cache,
    boolean enforceJoinOrder,
    int expBatchedJoins,
    String sql,
    String...expText
) {
    checkQueryPlan(cache,
        enforceJoinOrder,
        expBatchedJoins,
        new SqlFieldsQuery(sql),
        expText);

    sql = "select * from (" + sql + ")";

    checkQueryPlan(cache,
        enforceJoinOrder,
        expBatchedJoins,
        new SqlFieldsQuery(sql),
        expText);

    sql = "select * from (" + sql + ")";

    checkQueryPlan(cache,
        enforceJoinOrder,
        expBatchedJoins,
        new SqlFieldsQuery(sql),
        expText);
}
 
Example 20
/**
 * @param sql SQL.
 * @param cache Cache.
 */
private void checkQueryFails(final String sql, final IgniteCache<Object, Object> cache) {
    GridTestUtils.assertThrows(log, new Callable<Void>() {
        @Override public Void call() throws Exception {
            SqlFieldsQuery qry = new SqlFieldsQuery(sql);

            cache.query(qry).getAll();

            return null;
        }
    }, CacheException.class, null);
}
 
Example 21
/**
 * Output all employees those salary bigger than their direct manager (SQL-based fields queries and inner select).
 */
private static void sqlQueryEmployeesWithSalHigherManager() {
    IgniteCache<EmployeeKey, Employee> cache = Ignition.ignite().cache(EMPLOYEE_CACHE_NAME);

    // all employees those salary bigger than their direct manager.
    SqlFieldsQuery qry = new SqlFieldsQuery("select e.ename ,e.sal,m.ename,m.sal from Employee e, (select ename,empno,sal from Employee) m " +
        "where e.mgr = m.empno and e.sal > m.sal");
    log("==All employees those salary bigger than their direct manager==");
    logDecorated("||Employee||Emp.Salary||Manager||Mgr.Salary||", cache.query(qry).getAll());
}
 
Example 22
/**
 * @param cache Cache.
 * @param type Value type.
 * @param expCnt Expected count.
 */
private void checkCount1(IgniteCache cache, Class type, long expCnt) {
    SqlFieldsQuery qry = new SqlFieldsQuery("select _key, _val from " + type.getSimpleName());

    List<List<?>> res = cache.query(qry).getAll();

    assertEquals(expCnt, res.size());

    for (List<?> res0 : res)
        assertEquals(type, res0.get(1).getClass());
}
 
Example 23
Source Project: ignite   Source File: GridQueryProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param cctx Cache context.
 * @param qry Query.
 * @return Schema name.
 */
private String getSchemaName(GridCacheContext<?, ?> cctx, SqlFieldsQuery qry) {
    if (qry.getSchema() != null)
        return qry.getSchema();
    else if (cctx != null) {
        String cacheSchemaName = idx.schema(cctx.name());

        if (!F.isEmpty(cacheSchemaName))
            return cacheSchemaName;
    }

    return QueryUtils.DFLT_SCHEMA;
}
 
Example 24
Source Project: ignite   Source File: IgniteRepositoryQuery.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param prmtrs Prmtrs.
 * @return prepared query for execution
 */
@SuppressWarnings("deprecation")
@NotNull private Query prepareQuery(Object[] prmtrs) {
    Object[] parameters = prmtrs;
    String sql = qry.sql();

    switch (qry.options()) {
        case SORTING:
            sql = addSorting(new StringBuilder(sql), (Sort)parameters[parameters.length - 1]).toString();
            parameters = Arrays.copyOfRange(parameters, 0, parameters.length - 1);

            break;

        case PAGINATION:
            sql = addPaging(new StringBuilder(sql), (Pageable)parameters[parameters.length - 1]).toString();
            parameters = Arrays.copyOfRange(parameters, 0, parameters.length - 1);

            break;

        case NONE:
            // No-op.
    }

    if (qry.isFieldQuery()) {
        SqlFieldsQuery sqlFieldsQry = new SqlFieldsQuery(sql);
        sqlFieldsQry.setArgs(parameters);

        return sqlFieldsQry;
    }

    SqlQuery sqlQry = new SqlQuery(type, sql);
    sqlQry.setArgs(parameters);

    return sqlQry;
}
 
Example 25
Source Project: ignite   Source File: H2IndexesSystemViewTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param ignite Ignite.
 * @param sql Sql.
 * @param args Args.
 */
@SuppressWarnings("unchecked")
private List<List<?>> execSql(Ignite ignite, String sql, Object... args) {
    IgniteCache cache = ignite.cache(DEFAULT_CACHE_NAME);

    SqlFieldsQuery qry = new SqlFieldsQuery(sql);

    if (args != null && args.length > 0)
        qry.setArgs(args);

    return cache.query(qry).getAll();
}
 
Example 26
Source Project: ignite   Source File: GatewayProtectedCacheProxy.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public List<FieldsQueryCursor<List<?>>> queryMultipleStatements(SqlFieldsQuery qry) {
    CacheOperationGate opGate = onEnter();

    try {
        return delegate.queryMultipleStatements(qry);
    }
    finally {
        onLeave(opGate);
    }
}
 
Example 27
Source Project: ignite   Source File: SqlStatisticsUserQueriesFastTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check success metric in case of local select.
 *
 */
@Test
public void testLocalSelectSuccess() {
    assertMetricsIncrementedOnlyOnReducer(
        () -> cache.query(new SqlFieldsQuery("SELECT * FROM TAB WHERE ID < 100").setLocal(true)).getAll(),
        "success");
}
 
Example 28
Source Project: ignite   Source File: SqlQueriesTopologyMappingTest.java    License: Apache License 2.0 5 votes vote down vote up
/** */
@Test
public void testLocalCacheQueryMapping() throws Exception {
    IgniteEx ign0 = startGrid(0);

    IgniteCache<Object, Object> cache = ign0.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
        .setCacheMode(CacheMode.LOCAL)
        .setSqlSchema("PUBLIC")
        .setIndexedTypes(Integer.class, Integer.class));

    cache.put(1, 2);

    startGrid(1);

    SqlFieldsQuery qry = new SqlFieldsQuery("select * from Integer");

    {
        List<List<?>> res0 = grid(0).cache(DEFAULT_CACHE_NAME).query(qry).getAll();

        assertEquals(1, res0.size());
        assertEqualsCollections(Arrays.asList(1, 2), res0.get(0));
    }

    {
        List<List<?>> res1 = grid(1).cache(DEFAULT_CACHE_NAME).query(qry).getAll();

        assertTrue(res1.isEmpty());
    }
}
 
Example 29
Source Project: ignite   Source File: SqlDmlExample.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Example of conditional UPDATE query: raise salary by 10% to everyone who has Master degree.
 *
 * @param personCache Person cache.
 */
private static void update(IgniteCache<Long, Person> personCache) {
    String sql =
        "update Person set salary = salary * 1.1 " +
        "where resume = ?";

    personCache.query(new SqlFieldsQuery(sql).setArgs("Master"));
}
 
Example 30
Source Project: ignite   Source File: CacheMvccSelectForUpdateQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test that query throws exception with expected message.
 * @param qry SQL.
 * @param exMsg Expected message.
 * @param loc Local query flag.
 */
@SuppressWarnings("ThrowableNotThrown")
private void assertQueryThrows(String qry, String exMsg, boolean loc) {
    Ignite node = grid(0);

    GridTestUtils.assertThrows(null, new Callable<Object>() {
        @Override public Object call() {
            List r = node.cache("Person").query(new SqlFieldsQuery(qry).setLocal(loc)).getAll();

            return r;
        }
    }, IgniteSQLException.class, exMsg);
}