use of io.trino.sql.relational.RowExpression in project trino by trinodb.
the class TestExpressionOptimizer method testPossibleExponentialOptimizationTime.
@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime() {
RowExpression expression = constant(1L, BIGINT);
for (int i = 0; i < 100; i++) {
expression = new CallExpression(functionResolution.resolveOperator(ADD, ImmutableList.of(BIGINT, BIGINT)), ImmutableList.of(expression, constant(1L, BIGINT)));
}
optimizer.optimize(expression);
}
use of io.trino.sql.relational.RowExpression in project trino by trinodb.
the class TestExpressionOptimizer method testIfConstantOptimization.
@Test
public void testIfConstantOptimization() {
assertEquals(optimizer.optimize(ifExpression(constant(true, BOOLEAN), 1L, 2L)), constant(1L, BIGINT));
assertEquals(optimizer.optimize(ifExpression(constant(false, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
assertEquals(optimizer.optimize(ifExpression(constant(null, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
RowExpression condition = new CallExpression(functionResolution.resolveOperator(EQUAL, ImmutableList.of(BIGINT, BIGINT)), ImmutableList.of(constant(3L, BIGINT), constant(3L, BIGINT)));
assertEquals(optimizer.optimize(ifExpression(condition, 1L, 2L)), constant(1L, BIGINT));
}
use of io.trino.sql.relational.RowExpression in project trino by trinodb.
the class FunctionAssertions method assertCachedInstanceHasBoundedRetainedSizeInTx.
private void assertCachedInstanceHasBoundedRetainedSizeInTx(String projection, Session session) {
requireNonNull(projection, "projection is null");
Expression projectionExpression = createExpression(session, projection, getPlannerContext(), INPUT_TYPES);
RowExpression projectionRowExpression = toRowExpression(session, projectionExpression);
PageProcessor processor = runner.getExpressionCompiler().compilePageProcessor(Optional.empty(), ImmutableList.of(projectionRowExpression)).get();
// This is a heuristic to detect whether the retained size of cachedInstance is bounded.
// * The test runs at least 1000 iterations.
// * The test passes if max retained size doesn't refresh after
// 4x the number of iterations when max was last updated.
// * The test fails if retained size reaches 1MB.
// Note that 1MB is arbitrarily chosen and may be increased if a function implementation
// legitimately needs more.
long maxRetainedSize = 0;
int maxIterationCount = 0;
for (int iterationCount = 0; iterationCount < Math.max(1000, maxIterationCount * 4); iterationCount++) {
Iterator<Optional<Page>> output = processor.process(session.toConnectorSession(), new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), SOURCE_PAGE);
// consume the iterator
@SuppressWarnings("unused") Optional<Page> ignored = Iterators.getOnlyElement(output);
long retainedSize = processor.getProjections().stream().mapToLong(this::getRetainedSizeOfCachedInstance).sum();
if (retainedSize > maxRetainedSize) {
maxRetainedSize = retainedSize;
maxIterationCount = iterationCount;
}
if (maxRetainedSize >= 1048576) {
fail(format("The retained size of cached instance of function invocation is likely unbounded: %s", projection));
}
}
}
use of io.trino.sql.relational.RowExpression in project trino by trinodb.
the class FunctionAssertions method executeProjectionWithAllInTx.
private List<Object> executeProjectionWithAllInTx(String projection, Type expectedType, Session session, ExpressionCompiler compiler) {
requireNonNull(projection, "projection is null");
Expression projectionExpression = createExpression(session, projection, getPlannerContext(), INPUT_TYPES);
RowExpression projectionRowExpression = toRowExpression(session, projectionExpression);
List<Object> results = new ArrayList<>();
// If the projection does not need bound values, execute query using full engine
if (!needsBoundValue(projectionExpression)) {
MaterializedResult result = runner.execute("SELECT " + projection);
assertType(result.getTypes(), expectedType);
assertEquals(result.getTypes().size(), 1);
assertEquals(result.getMaterializedRows().size(), 1);
Object queryResult = Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
results.add(queryResult);
}
// execute as standalone operator
OperatorFactory operatorFactory = compileFilterProject(Optional.empty(), projectionRowExpression, compiler);
Object directOperatorValue = selectSingleValue(operatorFactory, expectedType, session);
results.add(directOperatorValue);
// interpret
Object interpretedValue = interpret(projectionExpression, expectedType, session);
results.add(interpretedValue);
// execute over normal operator
SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(Optional.empty(), projectionRowExpression, compiler);
Object scanOperatorValue = selectSingleValue(scanProjectOperatorFactory, expectedType, createNormalSplit(), session);
results.add(scanOperatorValue);
// execute over record set
Object recordValue = selectSingleValue(scanProjectOperatorFactory, expectedType, createRecordSetSplit(), session);
results.add(recordValue);
// If the projection does not need bound values, execute query using full engine
if (!needsBoundValue(projectionExpression)) {
MaterializedResult result = runner.execute("SELECT " + projection);
assertType(result.getTypes(), expectedType);
assertEquals(result.getTypes().size(), 1);
assertEquals(result.getMaterializedRows().size(), 1);
Object queryResult = Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
results.add(queryResult);
}
// validate type at end since some tests expect failure and for those UNKNOWN is used instead of actual type
assertEquals(projectionRowExpression.getType(), expectedType);
return results;
}
use of io.trino.sql.relational.RowExpression in project trino by trinodb.
the class BenchmarkEqualsConjunctsOperator method setup.
@Setup
public void setup() {
ExpressionCompiler expressionCompiler = functionResolution.getExpressionCompiler();
RowExpression projection = generateComplexComparisonProjection(FIELDS_COUNT, COMPARISONS_COUNT);
compiledProcessor = expressionCompiler.compilePageProcessor(Optional.empty(), ImmutableList.of(projection)).get();
}
Aggregations