Search in sources :

Example 1 with ResultFieldMetadata

use of org.apache.ignite.internal.sql.engine.ResultFieldMetadata 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)

Example 2 with ResultFieldMetadata

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

the class ResultSetMetadataImpl method fields.

/**
 * {@inheritDoc}
 */
@Override
public List<ResultFieldMetadata> fields() {
    if (fields == null) {
        List<ResultFieldMetadata> flds = new ArrayList<>(rowType.getFieldCount());
        for (int i = 0; i < rowType.getFieldCount(); ++i) {
            RelDataTypeField fld = rowType.getFieldList().get(i);
            flds.add(new ResultFieldMetadataImpl(fld.getName(), TypeUtils.nativeType(fld.getType()), fld.getIndex(), fld.getType().isNullable(), origins.get(i)));
            fields = flds;
        }
    }
    return fields;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) ResultFieldMetadata(org.apache.ignite.internal.sql.engine.ResultFieldMetadata) ArrayList(java.util.ArrayList)

Aggregations

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