Search in sources :

Example 1 with QueryProcessor

use of org.apache.ignite.internal.sql.engine.QueryProcessor in project ignite-3 by apache.

the class QueryChecker method check.

/**
 * Run checks.
 */
public void check() {
    // Check plan.
    QueryProcessor qryProc = getEngine();
    List<SqlCursor<List<?>>> explainCursors = qryProc.query("PUBLIC", "EXPLAIN PLAN FOR " + qry);
    Cursor<List<?>> explainCursor = explainCursors.get(0);
    List<List<?>> explainRes = getAllFromCursor(explainCursor);
    String actualPlan = (String) explainRes.get(0).get(0);
    if (!CollectionUtils.nullOrEmpty(planMatchers)) {
        for (Matcher<String> matcher : planMatchers) {
            assertThat("Invalid plan:\n" + actualPlan, actualPlan, matcher);
        }
    }
    if (exactPlan != null) {
        assertEquals(exactPlan, actualPlan);
    }
    // Check result.
    List<SqlCursor<List<?>>> cursors = qryProc.query("PUBLIC", qry, params);
    SqlCursor<List<?>> cur = cursors.get(0);
    if (expectedColumnNames != null) {
        List<String> colNames = cur.metadata().fields().stream().map(ResultFieldMetadata::name).collect(Collectors.toList());
        assertThat("Column names don't match", colNames, equalTo(expectedColumnNames));
    }
    if (expectedColumnTypes != null) {
        List<Type> colNames = cur.metadata().fields().stream().map(ResultFieldMetadata::type).map(Commons::nativeTypeToClass).collect(Collectors.toList());
        assertThat("Column types don't match", colNames, equalTo(expectedColumnTypes));
    }
    List<List<?>> res = CursorUtils.getAllFromCursor(cur);
    if (expectedResult != null) {
        if (!ordered) {
            // Avoid arbitrary order.
            res.sort(new ListComparator());
            expectedResult.sort(new ListComparator());
        }
        assertEqualsCollections(expectedResult, res);
    }
}
Also used : QueryProcessor(org.apache.ignite.internal.sql.engine.QueryProcessor) Type(java.lang.reflect.Type) SqlCursor(org.apache.ignite.internal.sql.engine.SqlCursor) ResultFieldMetadata(org.apache.ignite.internal.sql.engine.ResultFieldMetadata) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QueryProcessor (org.apache.ignite.internal.sql.engine.QueryProcessor)1 ResultFieldMetadata (org.apache.ignite.internal.sql.engine.ResultFieldMetadata)1 SqlCursor (org.apache.ignite.internal.sql.engine.SqlCursor)1