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)));
}
Aggregations