use of com.facebook.presto.block.BlockEncodingManager in project presto by prestodb.
the class TestExpressionOptimizer method testIfConstantOptimization.
@Test
public void testIfConstantOptimization() {
TypeRegistry typeManager = new TypeRegistry();
ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
assertEquals(optimizer.optimize(ifExpression(new ConstantExpression(true, BOOLEAN), 1L, 2L)), new ConstantExpression(1L, BIGINT));
assertEquals(optimizer.optimize(ifExpression(new ConstantExpression(false, BOOLEAN), 1L, 2L)), new ConstantExpression(2L, BIGINT));
assertEquals(optimizer.optimize(ifExpression(new ConstantExpression(null, BOOLEAN), 1L, 2L)), new ConstantExpression(2L, BIGINT));
Signature bigintEquals = internalOperator(OperatorType.EQUAL.name(), BOOLEAN.getTypeSignature(), BIGINT.getTypeSignature(), BIGINT.getTypeSignature());
RowExpression condition = new CallExpression(bigintEquals, BOOLEAN, ImmutableList.of(new ConstantExpression(3L, BIGINT), new ConstantExpression(3L, BIGINT)));
assertEquals(optimizer.optimize(ifExpression(condition, 1L, 2L)), new ConstantExpression(1L, BIGINT));
}
use of com.facebook.presto.block.BlockEncodingManager in project presto by prestodb.
the class TestExpressionOptimizer method testTryOptimization.
@Test
public void testTryOptimization() {
TypeRegistry typeManager = new TypeRegistry();
ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
Signature signature = new Signature("TRY", SCALAR, BIGINT.getTypeSignature());
RowExpression tryExpression = new CallExpression(signature, BIGINT, ImmutableList.of(new ConstantExpression(1L, BIGINT)));
assertEquals(optimizer.optimize(tryExpression), new ConstantExpression(1L, BIGINT));
tryExpression = new CallExpression(signature, BIGINT, ImmutableList.of(new InputReferenceExpression(1, BIGINT)));
assertEquals(optimizer.optimize(tryExpression), new InputReferenceExpression(1, BIGINT));
}
Aggregations