Search in sources :

Example 6 with InputReferenceExpression

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

the class TestPageProcessorCompiler method testNonDeterministicProject.

@Test
public void testNonDeterministicProject() throws Exception {
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression random = new CallExpression(new Signature("random", SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT)), BIGINT, singletonList(new ConstantExpression(10L, BIGINT)));
    InputReferenceExpression col0 = new InputReferenceExpression(0, BIGINT);
    CallExpression lessThanRandomExpression = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(col0, random));
    PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()).compilePageProcessor(new ConstantExpression(TRUE, BOOLEAN), ImmutableList.of(lessThanRandomExpression)).get();
    assertFalse(new DeterminismEvaluator(METADATA_MANAGER.getFunctionRegistry()).isDeterministic(lessThanRandomExpression));
    Page page = new Page(createLongDictionaryBlock(1, 100));
    Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(BOOLEAN));
    assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock);
}
Also used : InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) PageProcessor(com.facebook.presto.operator.PageProcessor) DeterminismEvaluator(com.facebook.presto.sql.relational.DeterminismEvaluator) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) Page(com.facebook.presto.spi.Page) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 7 with InputReferenceExpression

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

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

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

ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)9 InputReferenceExpression (com.facebook.presto.sql.relational.InputReferenceExpression)9 CallExpression (com.facebook.presto.sql.relational.CallExpression)7 Test (org.testng.annotations.Test)7 PageProcessor (com.facebook.presto.operator.PageProcessor)6 ExpressionCompiler (com.facebook.presto.sql.gen.ExpressionCompiler)6 Signature (com.facebook.presto.metadata.Signature)5 Page (com.facebook.presto.spi.Page)5 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)5 BlockAssertions.createLongDictionaryBlock (com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock)3 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)3 Scope (com.facebook.presto.bytecode.Scope)2 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)2 LambdaDefinitionExpression (com.facebook.presto.sql.relational.LambdaDefinitionExpression)2 RowExpression (com.facebook.presto.sql.relational.RowExpression)2 RowExpressionVisitor (com.facebook.presto.sql.relational.RowExpressionVisitor)2 VariableReferenceExpression (com.facebook.presto.sql.relational.VariableReferenceExpression)2 Slice (io.airlift.slice.Slice)2 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)1 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)1