Search in sources :

Example 1 with GridSqlQuerySplitter.mergeTableIdentifier

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuerySplitter.mergeTableIdentifier in project ignite by apache.

the class NoneOrSinglePartitionsQueryOptimizationsTest method runQuery.

/**
 * Runs query and checks that given sql query returns expect rows count.
 *
 * @param sqlQry SQL query
 * @param expResCnt Expected result rows count.
 * @param expMergeTbl Flag that signals that merge table is expected to be created.
 * @param explainSize Explain plan response size.
 * @param expOriginalQry Flag that signals that orignial sql query is expected as map query.
 * @throws Exception If failed.s
 */
@SuppressWarnings({ "ThrowableNotThrown", "unchecked" })
private void runQuery(String sqlQry, int expResCnt, boolean expMergeTbl, boolean expOriginalQry, int explainSize, Object... args) throws Exception {
    TestCommunicationSpi commSpi = (TestCommunicationSpi) grid(NODES_COUNT).configuration().getCommunicationSpi();
    commSpi.resetQueries();
    IgniteInternalFuture res = GridTestUtils.runAsync(() -> {
        QueryCursor cursor = orgCache.query(new SqlFieldsQuery(sqlQry).setArgs(args));
        Iterable iter = U.field(cursor, "iterExec");
        Iterator innerIter = U.field(iter.iterator(), "iter");
        if (expMergeTbl)
            assertTrue(innerIter instanceof H2ResultSetIterator);
        else
            assertTrue(innerIter instanceof ReduceIndexIterator);
        List<List<?>> all = new ArrayList<>();
        while (innerIter.hasNext()) all.add((List) innerIter.next());
        return all;
    });
    List<List<?>> rows = (List<List<?>>) res.get(RES_RETRIEVAL_TIMEOUT);
    assertNotNull(rows);
    assertEquals(expResCnt, rows.size());
    int mapQueriesCnt = commSpi.mapQueries.size();
    if (expOriginalQry) {
        assertEquals(1, mapQueriesCnt);
        assertEquals(sqlQry, commSpi.mapQueries.get(0));
    } else {
        for (String mapQry : commSpi.mapQueries) assertNotEquals(sqlQry, mapQry);
    }
    // Test explain query.
    QueryCursor explainCursor = orgCache.query(new SqlFieldsQuery("explain " + sqlQry).setArgs(args));
    List<List<?>> explainRes = explainCursor.getAll();
    assertEquals(explainSize, explainRes.size());
    if (expMergeTbl)
        assertTrue(((String) explainRes.get(explainRes.size() - 1).get(0)).contains(GridSqlQuerySplitter.mergeTableIdentifier(0)));
}
Also used : H2ResultSetIterator(org.apache.ignite.internal.processors.query.h2.H2ResultSetIterator) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) H2ResultSetIterator(org.apache.ignite.internal.processors.query.h2.H2ResultSetIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) QueryCursor(org.apache.ignite.cache.query.QueryCursor)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 QueryCursor (org.apache.ignite.cache.query.QueryCursor)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 H2ResultSetIterator (org.apache.ignite.internal.processors.query.h2.H2ResultSetIterator)1