use of com.facebook.presto.sql.relational.ConstantExpression 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.sql.relational.ConstantExpression 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));
}
use of com.facebook.presto.sql.relational.ConstantExpression in project presto by prestodb.
the class TestInCodeGenerator method testDate.
@Test
public void testDate() {
List<RowExpression> values = new ArrayList<>();
values.add(new ConstantExpression(1L, DATE));
values.add(new ConstantExpression(2L, DATE));
values.add(new ConstantExpression(3L, DATE));
assertEquals(checkSwitchGenerationCase(DATE, values), DIRECT_SWITCH);
for (long i = 4; i <= 32; ++i) {
values.add(new ConstantExpression(i, DATE));
}
assertEquals(checkSwitchGenerationCase(DATE, values), DIRECT_SWITCH);
values.add(new ConstantExpression(33L, DATE));
assertEquals(checkSwitchGenerationCase(DATE, values), SET_CONTAINS);
}
use of com.facebook.presto.sql.relational.ConstantExpression in project presto by prestodb.
the class CursorProcessorCompiler method fieldReferenceCompiler.
private static RowExpressionVisitor<Scope, BytecodeNode> fieldReferenceCompiler(Variable cursorVariable) {
return new RowExpressionVisitor<Scope, BytecodeNode>() {
@Override
public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) {
int field = node.getField();
Type type = node.getType();
Variable wasNullVariable = scope.getVariable("wasNull");
Class<?> javaType = type.getJavaType();
if (!javaType.isPrimitive() && javaType != Slice.class) {
javaType = Object.class;
}
IfStatement ifStatement = new IfStatement();
ifStatement.condition().setDescription(format("cursor.get%s(%d)", type, field)).getVariable(cursorVariable).push(field).invokeInterface(RecordCursor.class, "isNull", boolean.class, int.class);
ifStatement.ifTrue().putVariable(wasNullVariable, true).pushJavaDefault(javaType);
ifStatement.ifFalse().getVariable(cursorVariable).push(field).invokeInterface(RecordCursor.class, "get" + Primitives.wrap(javaType).getSimpleName(), javaType, int.class);
return ifStatement;
}
@Override
public BytecodeNode visitCall(CallExpression call, Scope scope) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public BytecodeNode visitConstant(ConstantExpression literal, Scope scope) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public BytecodeNode visitLambda(LambdaDefinitionExpression lambda, Scope context) {
throw new UnsupportedOperationException();
}
@Override
public BytecodeNode visitVariableReference(VariableReferenceExpression reference, Scope context) {
throw new UnsupportedOperationException();
}
};
}
Aggregations