Search in sources :

Example 1 with InputReferenceExpression

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

the class TestPageProcessorCompiler method testSanityColumnarDictionary.

@Test
public void testSanityColumnarDictionary() throws Exception {
    PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()).compilePageProcessor(new ConstantExpression(TRUE, BOOLEAN), ImmutableList.of(new InputReferenceExpression(0, VARCHAR))).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
    Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
}
Also used : PageProcessor(com.facebook.presto.operator.PageProcessor) InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) 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) Test(org.testng.annotations.Test)

Example 2 with InputReferenceExpression

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

the class TestPageProcessorCompiler method testSanityFilterOnDictionary.

@Test
public void testSanityFilterOnDictionary() throws Exception {
    CallExpression lengthVarchar = new CallExpression(new Signature("length", SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.VARCHAR)), BIGINT, ImmutableList.of(new InputReferenceExpression(0, VARCHAR)));
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(lengthVarchar, new ConstantExpression(10L, BIGINT)));
    PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()).compilePageProcessor(filter, ImmutableList.of(new InputReferenceExpression(0, VARCHAR))).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
    Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
    // test filter caching
    Page outputPage2 = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR));
    assertEquals(outputPage2.getPositionCount(), 100);
    assertTrue(outputPage2.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock2 = (DictionaryBlock) outputPage2.getBlock(0);
    // both output pages must have the same dictionary
    assertEquals(dictionaryBlock2.getDictionary(), dictionaryBlock.getDictionary());
}
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) 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 3 with InputReferenceExpression

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

the class LambdaBytecodeGenerator method variableReferenceCompiler.

private static RowExpressionVisitor<Scope, BytecodeNode> variableReferenceCompiler(Map<String, ParameterAndType> parameterMap) {
    return new RowExpressionVisitor<Scope, BytecodeNode>() {

        @Override
        public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) {
            throw new UnsupportedOperationException();
        }

        @Override
        public BytecodeNode visitCall(CallExpression call, Scope scope) {
            throw new UnsupportedOperationException();
        }

        @Override
        public BytecodeNode visitConstant(ConstantExpression literal, Scope scope) {
            throw new UnsupportedOperationException();
        }

        @Override
        public BytecodeNode visitLambda(LambdaDefinitionExpression lambda, Scope context) {
            throw new UnsupportedOperationException();
        }

        @Override
        public BytecodeNode visitVariableReference(VariableReferenceExpression reference, Scope context) {
            ParameterAndType parameterAndType = parameterMap.get(reference.getName());
            Parameter parameter = parameterAndType.getParameter();
            Class<?> type = parameterAndType.getType();
            return new BytecodeBlock().append(parameter).append(unboxPrimitiveIfNecessary(context, type));
        }
    };
}
Also used : InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) Scope(com.facebook.presto.bytecode.Scope) VariableReferenceExpression(com.facebook.presto.sql.relational.VariableReferenceExpression) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) RowExpressionVisitor(com.facebook.presto.sql.relational.RowExpressionVisitor) Parameter(com.facebook.presto.bytecode.Parameter) CallExpression(com.facebook.presto.sql.relational.CallExpression) LambdaDefinitionExpression(com.facebook.presto.sql.relational.LambdaDefinitionExpression)

Example 4 with InputReferenceExpression

use of com.facebook.presto.sql.relational.InputReferenceExpression 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();
        }
    };
}
Also used : InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) Variable(com.facebook.presto.bytecode.Variable) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) IfStatement(com.facebook.presto.bytecode.control.IfStatement) Type(com.facebook.presto.spi.type.Type) Scope(com.facebook.presto.bytecode.Scope) Slice(io.airlift.slice.Slice) VariableReferenceExpression(com.facebook.presto.sql.relational.VariableReferenceExpression) RowExpressionVisitor(com.facebook.presto.sql.relational.RowExpressionVisitor) CallExpression(com.facebook.presto.sql.relational.CallExpression) LambdaDefinitionExpression(com.facebook.presto.sql.relational.LambdaDefinitionExpression)

Example 5 with InputReferenceExpression

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

the class TestPageProcessorCompiler method testSanityRLE.

@Test
public void testSanityRLE() throws Exception {
    PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()).compilePageProcessor(new ConstantExpression(TRUE, BOOLEAN), ImmutableList.of(new InputReferenceExpression(0, BIGINT), new InputReferenceExpression(1, VARCHAR))).get();
    Slice varcharValue = Slices.utf8Slice("hello");
    Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 100));
    Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(BIGINT, VARCHAR));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L);
    RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1);
    assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue);
}
Also used : PageProcessor(com.facebook.presto.operator.PageProcessor) InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) Slice(io.airlift.slice.Slice) 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) 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