use of io.trino.sql.relational.CallExpression in project trino by trinodb.
the class TestExpressionOptimizer method testCastWithJsonParseOptimization.
@Test
public void testCastWithJsonParseOptimization() {
ResolvedFunction jsonParseFunction = functionResolution.resolveFunction(QualifiedName.of("json_parse"), fromTypes(VARCHAR));
// constant
ResolvedFunction jsonCastFunction = functionResolution.getCoercion(JSON, new ArrayType(INTEGER));
RowExpression jsonCastExpression = new CallExpression(jsonCastFunction, ImmutableList.of(call(jsonParseFunction, constant(utf8Slice("[1, 2]"), VARCHAR))));
RowExpression resultExpression = optimizer.optimize(jsonCastExpression);
assertInstanceOf(resultExpression, ConstantExpression.class);
Object resultValue = ((ConstantExpression) resultExpression).getValue();
assertInstanceOf(resultValue, IntArrayBlock.class);
assertEquals(toValues(INTEGER, (IntArrayBlock) resultValue), ImmutableList.of(1, 2));
// varchar to array
testCastWithJsonParseOptimization(jsonParseFunction, new ArrayType(VARCHAR), JSON_STRING_TO_ARRAY_NAME);
// varchar to map
testCastWithJsonParseOptimization(jsonParseFunction, mapType(INTEGER, VARCHAR), JSON_STRING_TO_MAP_NAME);
// varchar to row
testCastWithJsonParseOptimization(jsonParseFunction, RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), JSON_STRING_TO_ROW_NAME);
}
use of io.trino.sql.relational.CallExpression 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.CallExpression 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));
}
Aggregations