Search in sources :

Example 21 with RowExpression

use of com.facebook.presto.sql.relational.RowExpression in project presto by prestodb.

the class TestExpressionOptimizer method testPossibleExponentialOptimizationTime.

@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime() {
    TypeRegistry typeManager = new TypeRegistry();
    ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
    RowExpression expression = new ConstantExpression(1L, BIGINT);
    for (int i = 0; i < 100; i++) {
        Signature signature = internalOperator(OperatorType.ADD.name(), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT));
        expression = new CallExpression(signature, BIGINT, ImmutableList.of(expression, new ConstantExpression(1L, BIGINT)));
    }
    optimizer.optimize(expression);
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ExpressionOptimizer(com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) RowExpression(com.facebook.presto.sql.relational.RowExpression) TypeRegistry(com.facebook.presto.type.TypeRegistry) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 22 with RowExpression

use of com.facebook.presto.sql.relational.RowExpression 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));
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ExpressionOptimizer(com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) RowExpression(com.facebook.presto.sql.relational.RowExpression) TypeRegistry(com.facebook.presto.type.TypeRegistry) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 23 with RowExpression

use of com.facebook.presto.sql.relational.RowExpression 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));
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ExpressionOptimizer(com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) RowExpression(com.facebook.presto.sql.relational.RowExpression) TypeRegistry(com.facebook.presto.type.TypeRegistry) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 24 with RowExpression

use of com.facebook.presto.sql.relational.RowExpression in project presto by prestodb.

the class TestInCodeGenerator method testInteger.

@Test
public void testInteger() {
    List<RowExpression> values = new ArrayList<>();
    values.add(new ConstantExpression(Integer.MIN_VALUE, INTEGER));
    values.add(new ConstantExpression(Integer.MAX_VALUE, INTEGER));
    values.add(new ConstantExpression(3, INTEGER));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    values.add(new ConstantExpression(null, INTEGER));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    values.add(new CallExpression(new Signature(CAST, SCALAR, INTEGER.getTypeSignature(), DOUBLE.getTypeSignature()), INTEGER, Collections.singletonList(new ConstantExpression(12345678901234.0, DOUBLE))));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    for (int i = 6; i <= 32; ++i) {
        values.add(new ConstantExpression(i, INTEGER));
    }
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    values.add(new ConstantExpression(33, INTEGER));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), SET_CONTAINS);
}
Also used : ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) Signature(com.facebook.presto.metadata.Signature) ArrayList(java.util.ArrayList) RowExpression(com.facebook.presto.sql.relational.RowExpression) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 25 with RowExpression

use of com.facebook.presto.sql.relational.RowExpression 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);
}
Also used : ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) ArrayList(java.util.ArrayList) RowExpression(com.facebook.presto.sql.relational.RowExpression) Test(org.testng.annotations.Test)

Aggregations

RowExpression (com.facebook.presto.sql.relational.RowExpression)29 Signature (com.facebook.presto.metadata.Signature)12 CallExpression (com.facebook.presto.sql.relational.CallExpression)12 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)12 Test (org.testng.annotations.Test)9 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)8 Type (com.facebook.presto.spi.type.Type)8 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)7 ArrayList (java.util.ArrayList)7 Variable (com.facebook.presto.bytecode.Variable)6 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)5 Parameter (com.facebook.presto.bytecode.Parameter)5 Scope (com.facebook.presto.bytecode.Scope)5 IfStatement (com.facebook.presto.bytecode.control.IfStatement)5 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)4 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)4 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)4 LambdaDefinitionExpression (com.facebook.presto.sql.relational.LambdaDefinitionExpression)4