Search in sources :

Example 11 with CallExpression

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

the class TestPageProcessorCompiler method testNoCaching.

@Test
public void testNoCaching() throws Throwable {
    MetadataManager metadata = METADATA_MANAGER;
    ExpressionCompiler compiler = new ExpressionCompiler(metadata);
    ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
    ArrayType arrayType = new ArrayType(VARCHAR);
    Signature signature = new Signature("concat", SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature(), arrayType.getTypeSignature());
    projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(new InputReferenceExpression(0, arrayType), new InputReferenceExpression(1, arrayType))));
    ImmutableList<RowExpression> projections = projectionsBuilder.build();
    PageProcessor pageProcessor = compiler.compilePageProcessor(new ConstantExpression(true, BOOLEAN), projections).get();
    PageProcessor pageProcessor2 = compiler.compilePageProcessor(new ConstantExpression(true, BOOLEAN), projections).get();
    assertTrue(pageProcessor != pageProcessor2);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) PageProcessor(com.facebook.presto.operator.PageProcessor) ImmutableList(com.google.common.collect.ImmutableList) 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) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 12 with CallExpression

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

the class TestPageProcessorCompiler method testSanityFilterOnRLE.

@Test
public void testSanityFilterOnRLE() throws Exception {
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(new InputReferenceExpression(0, BIGINT), new ConstantExpression(10L, BIGINT)));
    PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()).compilePageProcessor(filter, ImmutableList.of(new InputReferenceExpression(0, BIGINT))).get();
    Page page = new Page(createRLEBlock(5L, 100));
    Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(BIGINT));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L);
}
Also used : InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) PageProcessor(com.facebook.presto.operator.PageProcessor) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) Page(com.facebook.presto.spi.Page) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 13 with CallExpression

use of com.facebook.presto.sql.relational.CallExpression 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 14 with CallExpression

use of com.facebook.presto.sql.relational.CallExpression 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 15 with CallExpression

use of com.facebook.presto.sql.relational.CallExpression 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)

Aggregations

CallExpression (com.facebook.presto.sql.relational.CallExpression)16 Signature (com.facebook.presto.metadata.Signature)11 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)11 RowExpression (com.facebook.presto.sql.relational.RowExpression)11 Test (org.testng.annotations.Test)9 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)7 InputReferenceExpression (com.facebook.presto.sql.relational.InputReferenceExpression)7 Parameter (com.facebook.presto.bytecode.Parameter)5 LambdaDefinitionExpression (com.facebook.presto.sql.relational.LambdaDefinitionExpression)5 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)4 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)4 Scope (com.facebook.presto.bytecode.Scope)4 PageProcessor (com.facebook.presto.operator.PageProcessor)4 ExpressionCompiler (com.facebook.presto.sql.gen.ExpressionCompiler)4 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)3 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)3 Variable (com.facebook.presto.bytecode.Variable)3 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)3 Page (com.facebook.presto.spi.Page)3 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)3