Search in sources :

Example 1 with InputReferenceExpression

use of io.prestosql.spi.relation.InputReferenceExpression in project hetu-core by openlookeng.

the class TestDeterminismEvaluator method testDeterminismEvaluator.

@Test
public void testDeterminismEvaluator() {
    RowExpressionDeterminismEvaluator determinismEvaluator = new RowExpressionDeterminismEvaluator(createTestMetadataManager());
    CallExpression random = new CallExpression(QualifiedObjectName.valueOfDefaultFunction("random").getObjectName(), new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction("random"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))), BIGINT, singletonList(constant(10L, BIGINT)), Optional.empty());
    assertFalse(determinismEvaluator.isDeterministic(random));
    InputReferenceExpression col0 = field(0, BIGINT);
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression lessThanExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, constant(10L, BIGINT)), Optional.empty());
    assertTrue(determinismEvaluator.isDeterministic(lessThanExpression));
    CallExpression lessThanRandomExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, random), Optional.empty());
    assertFalse(determinismEvaluator.isDeterministic(lessThanRandomExpression));
}
Also used : InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 2 with InputReferenceExpression

use of io.prestosql.spi.relation.InputReferenceExpression in project hetu-core by openlookeng.

the class TestStarTreeAggregationRule method testSupportedProjectNode.

@Test
public void testSupportedProjectNode() {
    // node is projectNode and expression instance of cast
    Assignments assignment1 = Assignments.builder().put(columnCustkey, new VariableReferenceExpression(columnCustkey.getName(), custkeyHandle.getType())).build();
    Optional<PlanNode> planNode1 = Optional.of(new ProjectNode(newId(), baseTableScan, assignment1));
    assertTrue(CubeOptimizerUtil.supportedProjectNode(planNode1));
    // not projectNode
    ListMultimap<Symbol, Symbol> mappings = ImmutableListMultimap.<Symbol, Symbol>builder().put(output, columnOrderkey).put(output, columnOrderkey).build();
    Optional<PlanNode> planNode2 = Optional.of(new UnionNode(newId(), ImmutableList.of(baseTableScan, baseTableScan), mappings, ImmutableList.copyOf(mappings.keySet())));
    assertFalse(CubeOptimizerUtil.supportedProjectNode(planNode2));
    // expression not instance of Cast
    Assignments assignment2 = Assignments.builder().put(columnCustkey, new InputReferenceExpression(1, INTEGER)).build();
    Optional<PlanNode> planNode3 = Optional.of(new ProjectNode(newId(), baseTableScan, assignment2));
    assertFalse(CubeOptimizerUtil.supportedProjectNode(planNode3));
    // expression is instance of SymbolReference OR Literal
    Assignments assignment3 = Assignments.builder().put(columnCustkey, // should be INTEGER
    new VariableReferenceExpression(columnCustkey.getName(), custkeyHandle.getType())).build();
    Optional<PlanNode> planNode4 = Optional.of(new ProjectNode(newId(), baseTableScan, assignment3));
    assertTrue(CubeOptimizerUtil.supportedProjectNode(planNode4));
    // empty node
    Optional<PlanNode> emptyPlanNode = Optional.empty();
    assertTrue(CubeOptimizerUtil.supportedProjectNode(emptyPlanNode));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) UnionNode(io.prestosql.spi.plan.UnionNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Symbol(io.prestosql.spi.plan.Symbol) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 3 with InputReferenceExpression

use of io.prestosql.spi.relation.InputReferenceExpression in project hetu-core by openlookeng.

the class CursorProcessorCompiler method fieldReferenceCompiler.

private static RowExpressionVisitor<BytecodeNode, Scope> fieldReferenceCompiler(Variable cursorVariable) {
    return new RowExpressionVisitor<BytecodeNode, Scope>() {

        @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(String.format(Locale.ROOT, "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 visitSpecialForm(SpecialForm specialForm, Scope context) {
            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(io.prestosql.spi.relation.InputReferenceExpression) Variable(io.airlift.bytecode.Variable) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) IfStatement(io.airlift.bytecode.control.IfStatement) Type(io.prestosql.spi.type.Type) Scope(io.airlift.bytecode.Scope) Slice(io.airlift.slice.Slice) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpressionVisitor(io.prestosql.spi.relation.RowExpressionVisitor) CallExpression(io.prestosql.spi.relation.CallExpression) SpecialForm(io.prestosql.spi.relation.SpecialForm) LambdaDefinitionExpression(io.prestosql.spi.relation.LambdaDefinitionExpression)

Example 4 with InputReferenceExpression

use of io.prestosql.spi.relation.InputReferenceExpression in project hetu-core by openlookeng.

the class TestPageProcessorCompiler method testNonDeterministicProject.

@Test
public void testNonDeterministicProject() {
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression random = new CallExpression(QualifiedObjectName.valueOfDefaultFunction("random").getObjectName(), new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction("random"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))), BIGINT, singletonList(constant(10L, BIGINT)), Optional.empty());
    InputReferenceExpression col0 = field(0, BIGINT);
    CallExpression lessThanRandomExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, random), Optional.empty());
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get();
    assertFalse(new RowExpressionDeterminismEvaluator(metadata).isDeterministic(lessThanRandomExpression));
    Page page = new Page(createLongDictionaryBlock(1, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock);
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) PageProcessor(io.prestosql.operator.project.PageProcessor) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.prestosql.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Page(io.prestosql.spi.Page) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 5 with InputReferenceExpression

use of io.prestosql.spi.relation.InputReferenceExpression in project hetu-core by openlookeng.

the class PageFunctionCompiler method compileProjectionInternal.

private Supplier<PageProjection> compileProjectionInternal(RowExpression projection, Optional<String> classNameSuffix) {
    requireNonNull(projection, "projection is null");
    if (projection instanceof InputReferenceExpression) {
        InputReferenceExpression input = (InputReferenceExpression) projection;
        InputPageProjection projectionFunction = new InputPageProjection(input.getField(), input.getType());
        return () -> projectionFunction;
    }
    if (projection instanceof ConstantExpression) {
        ConstantExpression constant = (ConstantExpression) projection;
        ConstantPageProjection projectionFunction = new ConstantPageProjection(constant.getValue(), constant.getType());
        return () -> projectionFunction;
    }
    PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(projection);
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    // generate Work
    ClassDefinition pageProjectionWorkDefinition = definePageProjectWorkClass(result.getRewrittenExpression(), callSiteBinder, classNameSuffix);
    Class<?> pageProjectionWorkClass;
    try {
        pageProjectionWorkClass = defineClass(pageProjectionWorkDefinition, Work.class, callSiteBinder.getBindings(), getClass().getClassLoader());
    } catch (Exception e) {
        throw new PrestoException(COMPILER_ERROR, e);
    }
    return () -> new GeneratedPageProjection(result.getRewrittenExpression(), determinismEvaluator.isDeterministic(result.getRewrittenExpression()), result.getInputChannels(), constructorMethodHandle(pageProjectionWorkClass, BlockBuilder.class, ConnectorSession.class, Page.class, SelectedPositions.class));
}
Also used : InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) ConstantPageProjection(io.prestosql.operator.project.ConstantPageProjection) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) PrestoException(io.prestosql.spi.PrestoException) GeneratedPageProjection(io.prestosql.operator.project.GeneratedPageProjection) Page(io.prestosql.spi.Page) ClassDefinition(io.airlift.bytecode.ClassDefinition) PrestoException(io.prestosql.spi.PrestoException) InputPageProjection(io.prestosql.operator.project.InputPageProjection) PageFieldsToInputParametersRewriter(io.prestosql.operator.project.PageFieldsToInputParametersRewriter) SelectedPositions(io.prestosql.operator.project.SelectedPositions) Work(io.prestosql.operator.Work) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Aggregations

InputReferenceExpression (io.prestosql.spi.relation.InputReferenceExpression)6 CallExpression (io.prestosql.spi.relation.CallExpression)4 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)3 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)3 Test (org.testng.annotations.Test)3 Scope (io.airlift.bytecode.Scope)2 Page (io.prestosql.spi.Page)2 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)2 Signature (io.prestosql.spi.function.Signature)2 LambdaDefinitionExpression (io.prestosql.spi.relation.LambdaDefinitionExpression)2 RowExpressionVisitor (io.prestosql.spi.relation.RowExpressionVisitor)2 SpecialForm (io.prestosql.spi.relation.SpecialForm)2 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)2 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)1 ClassDefinition (io.airlift.bytecode.ClassDefinition)1 Parameter (io.airlift.bytecode.Parameter)1 Variable (io.airlift.bytecode.Variable)1 IfStatement (io.airlift.bytecode.control.IfStatement)1 Slice (io.airlift.slice.Slice)1 BlockAssertions.createLongDictionaryBlock (io.prestosql.block.BlockAssertions.createLongDictionaryBlock)1