Search in sources :

Example 76 with SqlFieldsQuery

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

the class RunningQueriesTest method testClusterWideQueryIdGeneration.

/**
 * Check cluster wide query id generation.
 */
@Test
public void testClusterWideQueryIdGeneration() {
    newBarrier(1);
    IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 100; i++) {
        FieldsQueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("SELECT * FROM Integer WHERE 1 = 1"));
        Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1);
        assertEquals(1, runningQueries.size());
        GridRunningQueryInfo r = runningQueries.iterator().next();
        assertEquals(ignite.context().localNodeId() + "_" + r.id(), r.globalQueryId());
        cursor.close();
    }
}
Also used : List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 77 with SqlFieldsQuery

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

the class RunningQueriesTest method testQueryDML.

/**
 * Check tracking running queries for DML.
 *
 * @param dmlQry DML query.
 * @throws Exception Exception in case of failure.
 */
public void testQueryDML(String dmlQry) throws Exception {
    newBarrier(2);
    IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
    SqlFieldsQuery qry = new SqlFieldsQuery(dmlQry);
    IgniteInternalFuture<List<List<?>>> fut = GridTestUtils.runAsync(() -> cache.query(qry).getAll());
    assertWaitingOnBarrier();
    Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1);
    assertEquals(1, runningQueries.size());
    assertNoRunningQueries(ignite);
    runningQueries.forEach((info) -> Assert.assertEquals(qry.getSql(), info.query()));
    IgniteInternalFuture<Integer> fut1 = GridTestUtils.runAsync(() -> barrier.await());
    awaitTimeout();
    fut1.get(TIMEOUT_IN_MS);
    fut.get(TIMEOUT_IN_MS);
}
Also used : List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 78 with SqlFieldsQuery

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

the class RunningQueriesTest method testQueryDDL.

/**
 * Check tracking running queries for DDL.
 *
 * @throws Exception Exception in case of failure.
 */
public void testQueryDDL(String sql) throws Exception {
    newBarrier(2);
    IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
    SqlFieldsQuery qry = new SqlFieldsQuery(sql);
    IgniteInternalFuture<List<List<?>>> fut = GridTestUtils.runAsync(() -> cache.query(qry).getAll());
    assertWaitingOnBarrier();
    Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1);
    assertEquals(1, runningQueries.size());
    assertNoRunningQueries(ignite);
    runningQueries.forEach((info) -> Assert.assertEquals(qry.getSql(), info.query()));
    awaitTimeout();
    awaitTimeout();
    fut.get(TIMEOUT_IN_MS);
}
Also used : List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 79 with SqlFieldsQuery

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

the class IgniteSqlRoutingTest method testDateKeyAsTimestampParameter.

/**
 */
@Test
public void testDateKeyAsTimestampParameter() throws Exception {
    String cacheName = "dateCache";
    CacheConfiguration<Date, Date> ccfg = new CacheConfiguration<>(cacheName);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setIndexedTypes(Date.class, Date.class);
    IgniteCache<Date, Date> cache = grid(NODE_CLIENT).createCache(ccfg);
    try {
        int count = 30;
        Date[] values = new Date[count];
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        for (int i = 0; i < count; i++) {
            Date val = dateFormat.parse(String.format("%02d/06/2017", i + 1));
            cache.put(val, val);
            values[i] = val;
        }
        for (Date val : values) {
            Timestamp ts = new Timestamp(val.getTime());
            List<List<?>> result = cache.query(new SqlFieldsQuery("select _val from Date where _key = ?").setArgs(ts)).getAll();
            assertEquals(1, result.size());
            assertEquals(val, result.get(0).get(0));
        }
    } finally {
        cache.destroy();
    }
}
Also used : Timestamp(java.sql.Timestamp) Date(java.util.Date) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 80 with SqlFieldsQuery

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

the class IgniteSqlRoutingTest method testUnicastQuerySelectAffinityKeyEqualsConstant.

/**
 */
@Test
public void testUnicastQuerySelectAffinityKeyEqualsConstant() throws Exception {
    IgniteCache<CallKey, Call> cache = grid(NODE_CLIENT).cache(CACHE_CALL);
    List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select id, name, duration from Call where personId=100 order by id"), 1);
    assertEquals(2, result.size());
    checkResultsRow(result, 0, 1, "caller1", 100);
    checkResultsRow(result, 1, 2, "caller2", 200);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Aggregations

SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)679 Test (org.junit.Test)388 List (java.util.List)373 Ignite (org.apache.ignite.Ignite)170 ArrayList (java.util.ArrayList)136 IgniteCache (org.apache.ignite.IgniteCache)123 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)115 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)94 IgniteEx (org.apache.ignite.internal.IgniteEx)90 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)83 Transaction (org.apache.ignite.transactions.Transaction)80 CacheException (javax.cache.CacheException)67 Random (java.util.Random)55 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)53 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)52 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)45 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)41 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)32 HashMap (java.util.HashMap)31 Cache (javax.cache.Cache)31