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

The following examples show how to use org.apache.ignite.cache.query.SqlQuery. 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
Source Project: joyqueue   Source File: IgniteConfigDao.java    License: Apache License 2.0 6 votes vote down vote up
private SqlQuery buildQuery(ConfigQuery query) {
    IgniteDao.SimpleSqlBuilder sqlBuilder = IgniteDao.SimpleSqlBuilder.create(IgniteConfig.class);
    if (query != null) {
        if (query.getKey() != null && !query.getKey().isEmpty()) {
            sqlBuilder.and(COLUMN_CFG_KEY, query.getKey());
        }

        if (query.getGroup() != null && !query.getGroup().isEmpty()) {
            sqlBuilder.and(COLUMN_CFG_GROUP, query.getGroup());
        }
        if (StringUtils.isNotEmpty(query.getKeyword())) {
            sqlBuilder.and(COLUMN_CFG_KEY,query.getKeyword()).or(COLUMN_CFG_GROUP,query.getKeyword());
        }

    }
    return sqlBuilder.build();
}
 
Example 2
Source Project: joyqueue   Source File: IgnitePartitionGroupReplicaDao.java    License: Apache License 2.0 6 votes vote down vote up
private SqlQuery buildQuery(ReplicaQuery query) {

        IgniteDao.SimpleSqlBuilder builder = IgniteDao.SimpleSqlBuilder.create(IgnitePartitionGroupReplica.class);
        if (query != null) {
            if (query.getGroup() > -1) {
                builder.and(COLUMN_GROUP_NO, query.getGroup());
            }

            if (query.getTopic() != null && !query.getTopic().isEmpty()) {
                builder.and(COLUMN_TOPIC, query.getTopic());
            }
            if (query.getNamespace() != null) {
                builder.and(COLUMN_NAMESPACE, query.getNamespace());
            }

            if (query.getBrokerId() > 0) {
                builder.and(COLUMN_BROKER_ID, query.getBrokerId());
            }
        }

        return builder.build();
    }
 
Example 3
Source Project: joyqueue   Source File: IgniteTopicDao.java    License: Apache License 2.0 6 votes vote down vote up
private SqlQuery buildQuery(TopicQuery query) {
        IgniteDao.SimpleSqlBuilder sqlBuilder = IgniteDao.SimpleSqlBuilder.create(IgniteTopic.class);
        if (query != null) {
//            sqlBuilder.and("id !","__group_coordinators");
            if (query.getCode() != null && !query.getCode().isEmpty()) {
                sqlBuilder.and(IgniteTopic.COLUMN_CODE, query.getCode());
            }

            if (query.getNamespace() != null && !query.getNamespace().isEmpty()) {
                sqlBuilder.and(IgniteTopic.COLUMN_NAMESPACE, query.getNamespace());
            }
            if (query.getType() != null) {
                sqlBuilder.and(IgniteTopic.COLUMN_TYPE,query.getType());
            }
            if (StringUtils.isNotEmpty(query.getKeyword())) {
                sqlBuilder.like(IgniteTopic.COLUMN_CODE, query.getKeyword());
            }
        }
        return sqlBuilder.build();
    }
 
Example 4
Source Project: joyqueue   Source File: IgniteProducerDao.java    License: Apache License 2.0 6 votes vote down vote up
private SqlQuery buildQuery(ProducerQuery query) {
    IgniteDao.SimpleSqlBuilder sqlBuilder = IgniteDao.SimpleSqlBuilder.create(IgniteProducer.class);
    if (query != null) {
        if (query.getTopic() != null && !query.getTopic().isEmpty()) {
            sqlBuilder.and(COLUMN_TOPIC, query.getTopic());
        }
        if (query.getNamespace() != null && !query.getNamespace().isEmpty()) {
            sqlBuilder.and(COLUMN_NAMESPACE, query.getNamespace());
        }
        if (query.getApp() != null && !query.getApp().isEmpty()) {
            sqlBuilder.and(COLUMN_APP, query.getApp());
        }
        if (query.getClientType() > 0) {
            sqlBuilder.and(COLUMN_CLIENT_TYPE, query.getClientType());
        }
        if (query.getAppList() != null) {
            sqlBuilder.in(COLUMN_APP,query.getAppList());
        }
    }
    return sqlBuilder.build();
}
 
Example 5
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 testLocalSqlQueryFromClient() throws Exception {
    try (Ignite g = startClientGrid("client")) {
        IgniteCache<Integer, Integer> c = jcache(g, Integer.class, Integer.class);

        for (int i = 0; i < 10; i++)
            c.put(i, i);

        SqlQuery<Integer, Integer> qry = new SqlQuery<>(Integer.class, "_key >= 5 order by _key");

        qry.setLocal(true);

        assertThrowsWithCause(() -> c.query(qry), CacheException.class);
    }
}
 
Example 6
/** */
@Test
public void testDisappearedCacheWasNotFoundMessage() {
    SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JoinSqlTestHelper.JOIN_SQL).setArgs("Organization #0");

    qry.setDistributedJoins(true);

    try {
        personCache.query(qry).getAll();

        fail("No CacheException emitted.");
    }
    catch (CacheException e) {
        boolean exp = e.getMessage().contains("Cache not found on local node (was concurrently destroyed?)");

        if (!exp)
            throw e;
    }
}
 
Example 7
/** */
@Test
public void testDisappearedCacheCauseRetryMessage() {
    SqlQuery<String, JoinSqlTestHelper.Person> qry =
        new SqlQuery<String, JoinSqlTestHelper.Person>(JoinSqlTestHelper.Person.class, JoinSqlTestHelper.JOIN_SQL)
            .setArgs("Organization #0");

    qry.setDistributedJoins(true);

    try {
        personCache.query(qry).getAll();

        fail("No CacheException emitted.");
    }
    catch (CacheException e) {
        if (!e.getMessage().contains("Failed to reserve partitions for query (cache is not found on local node) ["))
            e.printStackTrace();

        assertTrue(e.getMessage(), e.getMessage().contains("Failed to reserve partitions for query (cache is not found on local node) ["));
    }
}
 
Example 8
Source Project: ignite   Source File: PlatformCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads sql query.
 *
 * @param reader Binary reader.
 * @return Query.
 */
private Query readSqlQuery(BinaryRawReaderEx reader) {
    boolean loc = reader.readBoolean();
    String sql = reader.readString();
    String typ = reader.readString();
    final int pageSize = reader.readInt();

    Object[] args = readQueryArgs(reader);

    boolean distrJoins = reader.readBoolean();
    int timeout = reader.readInt();
    boolean replicated = reader.readBoolean();

    return new SqlQuery(typ, sql)
            .setPageSize(pageSize)
            .setArgs(args)
            .setLocal(loc)
            .setDistributedJoins(distrJoins)
            .setTimeout(timeout, TimeUnit.MILLISECONDS)
            .setReplicatedOnly(replicated);
}
 
Example 9
Source Project: ignite   Source File: GridIndexingWithNoopSwapSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/** @throws Exception If failed. */
@Test
public void testQuery() throws Exception {
    IgniteCache<Integer, ObjectValue> cache = ignite.cache(DEFAULT_CACHE_NAME);

    int cnt = 10;

    for (int i = 0; i < cnt; i++)
        cache.getAndPut(i, new ObjectValue("test" + i, i));

    for (int i = 0; i < cnt; i++) {
        assertNotNull(cache.localPeek(i, ONHEAP_PEEK_MODES));

        cache.localEvict(Collections.singleton(i)); // Swap.
    }

    SqlQuery<Integer, ObjectValue> qry =
        new SqlQuery(ObjectValue.class, "intVal >= ? order by intVal");

    assertEquals(10, cache.query(qry.setArgs(0)).getAll().size());
}
 
Example 10
Source Project: ignite   Source File: CacheTtlAbstractSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param gridCnt Number of nodes.
 * @throws Exception If failed.
 */
private void checkSizeAfterLive(int gridCnt) throws Exception {
    for (int i = 0; i < gridCnt; ++i) {
        IgniteCache<Integer, Integer> cache = jcache(i);

        log.info("Size [node=" + i +
            ", heap=" + cache.localSize(ONHEAP) +
            ", offheap=" + cache.localSize(OFFHEAP) + ']');

        assertEquals(0, cache.localSize());
        assertEquals(0, cache.localSize(OFFHEAP));
        assertEquals(0, cache.query(new SqlQuery<>(Integer.class, "_val >= 0")).getAll().size());

        for (int key = 0; key < SIZE; key++)
            assertNull(cache.localPeek(key));
    }
}
 
Example 11
Source Project: ignite   Source File: IgniteCacheProxyImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Convert query arguments to BinaryObjects if binary marshaller used.
 *
 * @param qry Query.
 */
private void convertToBinary(final Query qry) {
    GridCacheContext<K, V> ctx = getContextSafe();

    if (ctx.binaryMarshaller()) {
        if (qry instanceof SqlQuery) {
            final SqlQuery sqlQry = (SqlQuery) qry;

            convertToBinary(sqlQry.getArgs());
        }
        else if (qry instanceof SpiQuery) {
            final SpiQuery spiQry = (SpiQuery) qry;

            convertToBinary(spiQry.getArgs());
        }
        else if (qry instanceof SqlFieldsQuery) {
            final SqlFieldsQuery fieldsQry = (SqlFieldsQuery) qry;

            convertToBinary(fieldsQry.getArgs());
        }
    }
}
 
Example 12
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 testArray() throws Exception {
    IgniteCache<Integer, ArrayObject> cache = jcache(Integer.class, ArrayObject.class);

    cache.put(1, new ArrayObject(new Long[] {1L, null, 3L}));
    cache.put(2, new ArrayObject(new Long[] {4L, 5L, 6L}));

    QueryCursor<Cache.Entry<Integer, ArrayObject>> q =
        cache.query(new SqlQuery<Integer, ArrayObject>(ArrayObject.class, "array_contains(arr, cast(? as long))").
            setArgs(4));

    Collection<Cache.Entry<Integer, ArrayObject>> res = q.getAll();

    assertEquals(1, res.size());

    Cache.Entry<Integer, ArrayObject> e = F.first(res);

    assertEquals(2, (int)e.getKey());
    assertArrayEquals(new Long[]{4L, 5L, 6L}, e.getValue().arr);
}
 
Example 13
/** {@inheritDoc} */
@Test
@Override public void testResponseMessageOnUnmarshallingFailed() {
    readCnt.set(Integer.MAX_VALUE);

    jcache(0).put(new TestKey(String.valueOf(++key)), "");

    //GridCacheQueryRequest unmarshalling failed test
    readCnt.set(1);

    try {
        jcache(0).query(new SqlQuery<TestKey, String>(String.class, "field like '" + key + "'")).getAll();

        fail("p2p marshalling failed, but error response was not sent");
    }
    catch (CacheException ignored) {
        // No-op.
    }
}
 
Example 14
Source Project: ignite   Source File: GridCacheOffheapIndexGetSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests behavior on offheaped entries.
 *
 * @throws Exception If failed.
 */
@Test
public void testGet() throws Exception {
    IgniteCache<Long, Long> cache = jcache(grid(0), cacheConfiguration(), Long.class, Long.class);

    for (long i = 0; i < 100; i++)
        cache.put(i, i);

    for (long i = 0; i < 100; i++)
        assertEquals((Long)i, cache.get(i));

    SqlQuery<Long, Long> qry = new SqlQuery<>(Long.class, "_val >= 90");

    List<Cache.Entry<Long, Long>> res = cache.query(qry).getAll();

    assertEquals(10, res.size());

    for (Cache.Entry<Long, Long> e : res) {
        assertNotNull(e.getKey());
        assertNotNull(e.getValue());
    }
}
 
Example 15
Source Project: ignite   Source File: GridCacheOffheapIndexGetSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testWithExpiryPolicy() throws Exception {
    IgniteCache<Long, Long> cache = jcache(grid(0), cacheConfiguration(), Long.class, Long.class);

    cache = cache.withExpiryPolicy(new TestExiryPolicy());

    for (long i = 0; i < 100; i++)
        cache.put(i, i);

    for (long i = 0; i < 100; i++)
        assertEquals((Long)i, cache.get(i));

    SqlQuery<Long, Long> qry = new SqlQuery<>(Long.class, "_val >= 90");

    List<Cache.Entry<Long, Long>> res = cache.query(qry).getAll();

    assertEquals(10, res.size());

    for (Cache.Entry<Long, Long> e : res) {
        assertNotNull(e.getKey());
        assertNotNull(e.getValue());
    }
}
 
Example 16
Source Project: ignite   Source File: TcpClientCache.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public <R> QueryCursor<R> query(Query<R> qry) {
    if (qry == null)
        throw new NullPointerException("qry");

    QueryCursor<R> res;

    if (qry instanceof ScanQuery)
        res = scanQuery((ScanQuery)qry);
    else if (qry instanceof SqlQuery)
        res = (QueryCursor<R>)sqlQuery((SqlQuery)qry);
    else if (qry instanceof SqlFieldsQuery)
        res = (QueryCursor<R>)query((SqlFieldsQuery)qry);
    else
        throw new IllegalArgumentException(
            String.format("Query of type [%s] is not supported", qry.getClass().getSimpleName())
        );

    return res;
}
 
Example 17
Source Project: ignite   Source File: H2RowCacheSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @param rowCache Row cache.
 * @param key Key to find.
 * @return Row's link.
 */
private long getLinkForKey(String cacheName, H2RowCache rowCache, int key) {
    grid().cache(cacheName)
        .query(new SqlQuery(Value.class, "_key = " + key)).getAll().size();

    ConcurrentLinkedHashMap<Long, H2CacheRow> rowsMap = GridTestUtils.getFieldValue(rowCache, "rows");

    for (Map.Entry<Long, H2CacheRow> e : rowsMap.entrySet()) {
        H2CacheRow val = e.getValue();

        KeyCacheObject rowKey = val.key();

        if ((Integer)rowKey.value(null, false) == key)
            return e.getKey();
    }

    fail("Row cache doesn't contain key [key=" + key + ']');

    return -1;
}
 
Example 18
Source Project: joyqueue   Source File: IgniteConsumerConfigDao.java    License: Apache License 2.0 5 votes vote down vote up
private SqlQuery buildSqlQuery(ConsumerQuery query) {
    IgniteDao.SimpleSqlBuilder sqlBuilder = IgniteDao.SimpleSqlBuilder.create(IgniteConsumerConfig.class);
    if (query != null) {
        if (query.getTopic() != null && !query.getTopic().isEmpty()) {
            sqlBuilder.and(COLUMN_TOPIC, query.getTopic());
        }
        if (query.getNamespace() != null && !query.getNamespace().isEmpty()) {
            sqlBuilder.and(COLUMN_NAMESPACE, query.getNamespace());
        }
        if (query.getApp() != null && !query.getApp().isEmpty()) {
            sqlBuilder.and(COLUMN_APP, query.getApp());
        }
    }
    return sqlBuilder.build();
}
 
Example 19
Source Project: joyqueue   Source File: IgniteAppTokenDao.java    License: Apache License 2.0 5 votes vote down vote up
private SqlQuery buildQuery(AppTokenQuery query) {
    IgniteDao.SimpleSqlBuilder sqlBuilder = IgniteDao.SimpleSqlBuilder.create(IgniteAppToken.class);
    if (query != null) {
        if (query.getApp() != null && !query.getApp().isEmpty()) {
            sqlBuilder.and(COLUMN_APP, query.getApp());
        }

        if (query.getToken() != null && !query.getToken().isEmpty()) {
            sqlBuilder.and(COLUMN_TOKEN, query.getToken());
        }

    }
    return sqlBuilder.build();
}
 
Example 20
Source Project: joyqueue   Source File: IgniteProducerConfigDao.java    License: Apache License 2.0 5 votes vote down vote up
private SqlQuery buildQuery(ProducerQuery query) {
    IgniteDao.SimpleSqlBuilder sqlBuilder = IgniteDao.SimpleSqlBuilder.create(IgniteProducerConfig.class);
    if (query != null) {
        if (query.getTopic() != null && !query.getTopic().isEmpty()) {
            sqlBuilder.and(COLUMN_TOPIC, query.getTopic());
        }
        if (query.getNamespace() != null && !query.getNamespace().isEmpty()) {
            sqlBuilder.and(COLUMN_NAMESPACE, query.getNamespace());
        }
        if (query.getApp() != null && !query.getApp().isEmpty()) {
            sqlBuilder.and(COLUMN_APP, query.getApp());
        }
    }
    return sqlBuilder.build();
}
 
Example 21
Source Project: ignite   Source File: IgniteTxMultiNodeAbstractTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-11956")
@Test
public void testRemoveInTxQueried() throws Exception {
    //resetLog4j(Level.INFO, true, GridCacheTxManager.class.getPackage().getName());

    startGrids(GRID_CNT);

    try {
        IgniteCache<String, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);

        cache.put(RMVD_CNTR_KEY, 0);

        for (int i = 0; i < GRID_CNT * RETRIES; i++)
            cache.put(String.valueOf(i), i);

        for (int i = 0; i < RETRIES; i++)
            for (int j = 0; j < GRID_CNT; j++)
                assertEquals(i, grid(j).cache(DEFAULT_CACHE_NAME).get(String.valueOf(i)));

        Collection<Cache.Entry<String, Integer>> entries =
            cache.query(new SqlQuery<String, Integer>(Integer.class, " _val >= 0")).getAll();

        assertFalse(entries.isEmpty());

        cntrRmvd.set(0);

        grid(0).compute().broadcast(new RemoveInTxJobQueried());

        for (int i = 0; i < GRID_CNT * RETRIES; i++)
            for (int ii = 0; ii < GRID_CNT; ii++)
                assertEquals(null, grid(ii).cache(DEFAULT_CACHE_NAME).get(Integer.toString(i)));

        assertEquals(-GRID_CNT * RETRIES, grid(0).cache(DEFAULT_CACHE_NAME).get(RMVD_CNTR_KEY));
    }
    finally {
        stopAllGrids();
    }
}
 
Example 22
Source Project: joyqueue   Source File: IgniteNamespaceDao.java    License: Apache License 2.0 5 votes vote down vote up
SqlQuery buildQuery(NamespaceQuery query) {
    IgniteDao.SimpleSqlBuilder builder = IgniteDao.SimpleSqlBuilder.create(IgniteNamespace.class);
    if (query != null && (query.getCode() != null && !query.getCode().isEmpty())) {
        builder.and(COLUMN_CODE, query.getCode());
    }

    return builder.build();
}
 
Example 23
Source Project: spring-boot-ignite   Source File: IgniteAlertsStore.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<AlertEntry> getAlertForServiceId(String serviceId) {
    final String sql = "serviceId = ?";
    SqlQuery<String, AlertEntry> query = new SqlQuery<>(AlertEntry.class, sql);
    query.setArgs(serviceId);
    return Optional.ofNullable(getAlertsCache().query(query).getAll()
            .stream()
            .map(Cache.Entry::getValue)
            .collect(Collectors.toList()))
            .orElseThrow(() -> new ResourceNotFoundException(String.format("Alert for %s not found", serviceId)));
}
 
Example 24
Source Project: spring-boot-ignite   Source File: IgniteAlertsStore.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<AlertEntry> getAllAlerts() {
    final String sql = "select * from AlertEntry";
    SqlQuery<String, AlertEntry> query = new SqlQuery<>(AlertEntry.class, sql);
    return getAlertsCache().query(query).getAll()
            .stream()
            .map(Cache.Entry::getValue)
            .collect(Collectors.toList());

}
 
Example 25
Source Project: spring-boot-ignite   Source File: IgniteAlertsSoreTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	Cache.Entry entry = new CacheEntryImpl("serviceId", AlertEntry.builder().errorCode("errorCode").build());
	when(ignite.cache(CacheNames.Alerts.name())).thenReturn(igniteCache);
	when(igniteAlertsStore.getAlertsCache()).thenReturn(igniteCache);
	when(igniteCache.query(any(SqlQuery.class))).thenReturn(queryCursor);
	when(queryCursor.getAll()).thenReturn(Arrays.asList(entry));

}
 
Example 26
/**
 * The method represents set of conditions on salary ranges.
 */
private static void sqlQuery() {
    IgniteCache<EmployeeKey, Employee> cache = Ignition.ignite().cache(EMPLOYEE_CACHE_NAME);

    // Create query which selects salaries based on range.
    SqlQuery<EmployeeKey, Employee> qry = new SqlQuery<>(Employee.class, "sal > ? and sal <= ?");

    // Execute queries for salary ranges.
    logDecorated("==Employee with salaries between 0 and 1000==", cache.query(qry.setArgs(0, 1000)).getAll());

    logDecorated("==Employee with salaries between 1000 and 2000==", cache.query(qry.setArgs(1000, 2000)).getAll());

    logDecorated("==Employee with salaries greater than 2000==", cache.query(qry.setArgs(2000, Integer.MAX_VALUE)).getAll());
}
 
Example 27
Source Project: ignite   Source File: GridCacheDynamicLoadOnClientTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test from client node to get cache elements through cache API.
 */
@Test
public void testClientSqlQuery() {
    SqlQuery<Integer, Person> qry = new SqlQuery<>(PERSON_CACHE, "FROM " + PERSON_CACHE);

    Assert.assertEquals(CACHE_ELEMENT_COUNT, clientNode.getOrCreateCache(PERSON_CACHE).query(qry).getAll().size());
}
 
Example 28
Source Project: ignite   Source File: IgniteH2Indexing.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override public SqlFieldsQuery generateFieldsQuery(String cacheName, SqlQuery qry) {
    String schemaName = schema(cacheName);

    String type = qry.getType();

    H2TableDescriptor tblDesc = schemaMgr.tableForType(schemaName, cacheName, type);

    if (tblDesc == null)
        throw new IgniteSQLException("Failed to find SQL table for type: " + type,
            IgniteQueryErrorCode.TABLE_NOT_FOUND);

    String sql;

    try {
        sql = generateFieldsQueryString(qry.getSql(), qry.getAlias(), tblDesc);
    }
    catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }

    SqlFieldsQuery res = new SqlFieldsQuery(sql);

    res.setArgs(qry.getArgs());
    res.setDistributedJoins(qry.isDistributedJoins());
    res.setLocal(qry.isLocal());
    res.setPageSize(qry.getPageSize());
    res.setPartitions(qry.getPartitions());
    res.setReplicatedOnly(qry.isReplicatedOnly());
    res.setSchema(schemaName);
    res.setSql(sql);

    if (qry.getTimeout() > 0)
        res.setTimeout(qry.getTimeout(), TimeUnit.MILLISECONDS);

    return res;
}
 
Example 29
/**
 * Tests correct query execution with disabled re-balancing.
 */
@Test
public void testQueryNoRebalance() {
    IgniteCache<Object, Object> cache = grid().cache(DEFAULT_CACHE_NAME);

    cache.put(1, 1);

    QueryCursor<Cache.Entry<Integer, Integer>> qry =
        cache.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= 0"));

    assertEquals("Bad results count", 1, qry.getAll().size());
}
 
Example 30
Source Project: ignite   Source File: QueryDataPageScanTest.java    License: Apache License 2.0 5 votes vote down vote up
private void checkSqlQuery(IgniteCache<Long,TestData> cache, Boolean dataPageScanEnabled) {
    DirectPageScanIndexing.expectedDataPageScanEnabled = dataPageScanEnabled;

    assertTrue(cache.query(new SqlQuery<>(TestData.class,
        "from TestData use index() where check_scan_flag(?,false)") // Force full scan with USE INDEX()
        .setArgs(DirectPageScanIndexing.expectedDataPageScanEnabled)
        )
        .getAll().isEmpty());

    checkSqlLastFindDataPageScan(dataPageScanEnabled);
}