use of io.trino.operator.OperatorFactory in project trino by trinodb.
the class FunctionAssertions method executeFilterWithAll.
private List<Boolean> executeFilterWithAll(String filter, Session session, boolean executeWithNoInputColumns, ExpressionCompiler compiler) {
requireNonNull(filter, "filter is null");
Expression filterExpression = createExpression(session, filter, getPlannerContext(), INPUT_TYPES);
RowExpression filterRowExpression = toRowExpression(session, filterExpression);
List<Boolean> results = new ArrayList<>();
// execute as standalone operator
OperatorFactory operatorFactory = compileFilterProject(Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
results.add(executeFilter(operatorFactory, session));
if (executeWithNoInputColumns) {
// execute as standalone operator
operatorFactory = compileFilterWithNoInputColumns(filterRowExpression, compiler);
results.add(executeFilterWithNoInputColumns(operatorFactory, session));
}
// interpret
Boolean interpretedValue = (Boolean) interpret(filterExpression, BOOLEAN, session);
if (interpretedValue == null) {
interpretedValue = false;
}
results.add(interpretedValue);
// execute over normal operator
SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
boolean scanOperatorValue = executeFilter(scanProjectOperatorFactory, createNormalSplit(), session);
results.add(scanOperatorValue);
// execute over record set
boolean recordValue = executeFilter(scanProjectOperatorFactory, createRecordSetSplit(), session);
results.add(recordValue);
// If the filter does not need bound values, execute query using full engine
if (!needsBoundValue(filterExpression)) {
MaterializedResult result = runner.execute("SELECT TRUE WHERE " + filter);
assertEquals(result.getTypes().size(), 1);
Boolean queryResult;
if (result.getMaterializedRows().isEmpty()) {
queryResult = false;
} else {
assertEquals(result.getMaterializedRows().size(), 1);
queryResult = (Boolean) Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
}
results.add(queryResult);
}
return results;
}
use of io.trino.operator.OperatorFactory in project trino by trinodb.
the class TestUnnestOperator method testUnnest.
@Test
public void testUnnest() {
Type arrayType = new ArrayType(BIGINT);
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false, false);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L).row(1L, 3L, null, null).row(2L, 99L, null, null).row(6L, 7L, 9L, 10L).row(6L, 8L, 11L, 12L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.operator.OperatorFactory in project trino by trinodb.
the class TestUnnestOperator method testOuterUnnestWithOrdinality.
@Test
public void testOuterUnnestWithOrdinality() {
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
Type arrayType = new ArrayType(BIGINT);
Type elementType = RowType.anonymous(ImmutableList.of(BIGINT, DOUBLE, VARCHAR));
Type arrayOfRowType = new ArrayType(elementType);
List<Page> input = rowPagesBuilder(BIGINT, mapType, arrayType, arrayOfRowType).row(1, mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(1, 2, 6, 7)), arrayBlockOf(BIGINT, 3), arrayBlockOf(elementType, ImmutableList.of(4, 5.5, "a"))).row(2, null, null, null).pageBreak().row(3, null, null, null).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2, 3), ImmutableList.of(mapType, arrayType, arrayOfRowType), true, true);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, DOUBLE, VARCHAR, BIGINT).row(1L, 1L, 2L, 3L, 4L, 5.5, "a", 1L).row(1L, 6L, 7L, null, null, null, null, 2L).row(2L, null, null, null, null, null, null, null).row(3L, null, null, null, null, null, null, null).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.operator.OperatorFactory in project trino by trinodb.
the class TestUnnestOperator method testUnnestWithOrdinality.
@Test
public void testUnnestWithOrdinality() {
Type arrayType = new ArrayType(BIGINT);
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), true, false);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L, 1L).row(1L, 3L, null, null, 2L).row(2L, 99L, null, null, 1L).row(6L, 7L, 9L, 10L, 1L).row(6L, 8L, 11L, 12L, 2L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.operator.OperatorFactory in project trino by trinodb.
the class TestUnnestOperator method testUnnestNonNumericDoubles.
@Test
public void testUnnestNonNumericDoubles() {
Type arrayType = new ArrayType(DOUBLE);
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(DOUBLE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NaN), mapBlockOf(BIGINT, DOUBLE, ImmutableMap.of(1, NEGATIVE_INFINITY, 2, POSITIVE_INFINITY, 3, NaN))).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false, false);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE, BIGINT, DOUBLE).row(1L, NEGATIVE_INFINITY, 1L, NEGATIVE_INFINITY).row(1L, POSITIVE_INFINITY, 2L, POSITIVE_INFINITY).row(1L, NaN, 3L, NaN).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Aggregations