Search in sources :

Example 91 with SqlFieldsQuery

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

the class SqlQueryHistorySelfTest method testSqlFieldsQueryHistoryFailed.

/**
 * Test metrics for failed SQL queries.
 */
@Test
public void testSqlFieldsQueryHistoryFailed() {
    SqlFieldsQuery qry = new SqlFieldsQuery("select * from String where fail()=1");
    checkQueryFailedMetrics(qry);
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 92 with SqlFieldsQuery

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

the class SqlQueryHistorySelfTest method testSqlFieldsQueryHistoryNotFullyFetched.

/**
 * Test metrics for SQL fields queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlFieldsQueryHistoryNotFullyFetched() throws Exception {
    SqlFieldsQuery qry = new SqlFieldsQuery("select * from String");
    qry.setPageSize(10);
    checkQueryNotFullyFetchedMetrics(qry, false);
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 93 with SqlFieldsQuery

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

the class SqlQueryHistorySelfTest method testQueryHistoryForDmlAndDdl.

/**
 * Test metrics eviction.
 *
 * @throws Exception In case of error.
 */
@Test
public void testQueryHistoryForDmlAndDdl() throws Exception {
    IgniteCache<Integer, String> cache = queryNode().context().cache().jcache("A");
    List<String> cmds = Arrays.asList("create table TST(id int PRIMARY KEY, name varchar)", "insert into TST(id) values(1)", "commit");
    cmds.forEach((cmd) -> cache.query(new SqlFieldsQuery(cmd)).getAll());
    checkSeriesCommand(cmds);
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 94 with SqlFieldsQuery

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

the class SqlSchemaSelfTest method testQueryWithoutCacheOnPublicSchema.

/**
 * Test query without caches.
 *
 * @throws Exception If failed.
 */
@Test
public void testQueryWithoutCacheOnPublicSchema() throws Exception {
    GridQueryProcessor qryProc = node.context().query();
    SqlFieldsQuery qry = new SqlFieldsQuery("SELECT 1").setSchema("PUBLIC");
    List<List<?>> res = qryProc.querySqlFields(qry, true).getAll();
    assertEquals(1, res.size());
    assertEquals(1, res.get(0).size());
    assertEquals(1, res.get(0).get(0));
    Iterator<List<?>> iter = qryProc.querySqlFields(qry, true).iterator();
    assertTrue(iter.hasNext());
    List<?> row = iter.next();
    assertEquals(1, row.size());
    assertEquals(1, row.get(0));
    assertFalse(iter.hasNext());
}
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 95 with SqlFieldsQuery

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

the class IgniteSqlSplitterSelfTest method checkQueryWithGroupsAndAggrMixed.

/**
 * Query with distinct aggregates and groups
 */
private void checkQueryWithGroupsAndAggrMixed(IgniteCache<Integer, Value> cache) {
    try (QueryCursor<List<?>> qry = cache.query(new SqlFieldsQuery("SELECT fst, count(snd), sum(snd), avg(snd), avg(cast(snd as double)), min(snd), max(snd)," + "count(distinct snd), sum(distinct snd), avg(distinct snd), avg(distinct cast(snd as double)), " + "min(distinct snd), max(distinct snd) FROM Value GROUP BY fst"))) {
        List<List<?>> result = qry.getAll();
        assertEquals(6, result.size());
        List<?> row = result.get(0);
        assertEquals("fst", 1, ((Number) row.get(0)).intValue());
        assertEquals("count", 3L, ((Number) row.get(1)).longValue());
        assertEquals("sum", 9L, ((Number) row.get(2)).longValue());
        assertEquals("avg", 3, ((Integer) row.get(3)).intValue());
        assertEquals("avg dbl", 3.0d, ((Number) row.get(4)).doubleValue(), 0.001);
        assertEquals("min", 3, ((Integer) row.get(5)).intValue());
        assertEquals("max", 3, ((Integer) row.get(6)).intValue());
        assertEquals("count distinct", 1L, ((Number) row.get(7)).longValue());
        assertEquals("sum distinct", 3L, ((Number) row.get(8)).longValue());
        assertEquals("avg distinct", 3, ((Integer) row.get(9)).intValue());
        assertEquals("avg distinct dbl", 3.0d, ((Number) row.get(10)).doubleValue(), 0.001);
        assertEquals("min distinct", 3, ((Integer) row.get(11)).intValue());
        assertEquals("max distinct", 3, ((Integer) row.get(12)).intValue());
        row = result.get(1);
        assertEquals("fst", 2, ((Number) row.get(0)).intValue());
        assertEquals("count", 3L, ((Number) row.get(1)).longValue());
        assertEquals("sum", 6L, ((Number) row.get(2)).longValue());
        assertEquals("avg", 2, ((Integer) row.get(3)).intValue());
        assertEquals("avg dbl", 2.0d, ((Number) row.get(4)).doubleValue(), 0.001);
        assertEquals("min", 1, ((Integer) row.get(5)).intValue());
        assertEquals("max", 3, ((Integer) row.get(6)).intValue());
        assertEquals("count distinct", 3L, ((Number) row.get(7)).longValue());
        assertEquals("sum distinct", 6L, ((Number) row.get(8)).longValue());
        assertEquals("avg distinct", 2, ((Integer) row.get(9)).intValue());
        assertEquals("avg distinct dbl", 2.0d, ((Number) row.get(10)).doubleValue(), 0.001);
        assertEquals("min distinct", 1, ((Integer) row.get(11)).intValue());
        assertEquals("max distinct", 3, ((Integer) row.get(12)).intValue());
        row = result.get(2);
        assertEquals("fst", 3, ((Number) row.get(0)).intValue());
        assertEquals("count", 6L, ((Number) row.get(1)).longValue());
        assertEquals("sum", 9L, ((Number) row.get(2)).longValue());
        assertEquals("avg", 1, ((Integer) row.get(3)).intValue());
        assertEquals("avg dbl", 1.5d, ((Number) row.get(4)).doubleValue(), 0.001);
        assertEquals("min", 1, ((Integer) row.get(5)).intValue());
        assertEquals("max", 2, ((Integer) row.get(6)).intValue());
        assertEquals("count distinct", 2L, ((Number) row.get(7)).longValue());
        assertEquals("sum distinct", 3L, ((Number) row.get(8)).longValue());
        assertEquals("avg distinct", 1, ((Integer) row.get(9)).intValue());
        assertEquals("avg distinct dbl", 1.5d, ((Number) row.get(10)).doubleValue(), 0.001);
        assertEquals("min distinct", 1, ((Integer) row.get(11)).intValue());
        assertEquals("max distinct", 2, ((Integer) row.get(12)).intValue());
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

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