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