Search in sources :

Example 21 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class TestPruneWindowColumns method buildProjectedWindow.

private static PlanNode buildProjectedWindow(PlanBuilder p, Predicate<Symbol> projectionFilter, Predicate<Symbol> sourceFilter) {
    Symbol orderKey = p.symbol("orderKey");
    Symbol partitionKey = p.symbol("partitionKey");
    Symbol hash = p.symbol("hash");
    Symbol startValue1 = p.symbol("startValue1");
    Symbol startValue2 = p.symbol("startValue2");
    Symbol endValue1 = p.symbol("endValue1");
    Symbol endValue2 = p.symbol("endValue2");
    Symbol input1 = p.symbol("input1");
    Symbol input2 = p.symbol("input2");
    Symbol unused = p.symbol("unused");
    Symbol output1 = p.symbol("output1");
    Symbol output2 = p.symbol("output2");
    List<Symbol> inputs = ImmutableList.of(orderKey, partitionKey, hash, startValue1, startValue2, endValue1, endValue2, input1, input2, unused);
    List<Symbol> outputs = ImmutableList.<Symbol>builder().addAll(inputs).add(output1, output2).build();
    return p.project(Assignments.copyOf(outputs.stream().filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> p.variable(v.getName(), BIGINT)))), p.window(new WindowNode.Specification(ImmutableList.of(partitionKey), Optional.of(new OrderingScheme(ImmutableList.of(orderKey), ImmutableMap.of(orderKey, SortOrder.ASC_NULLS_FIRST)))), ImmutableMap.of(output1, new WindowNode.Function(call(FUNCTION_NAME, FUNCTION_HANDLE, BIGINT, ImmutableList.of(p.variable(input1.getName()))), ImmutableList.of(p.variable(input1.getName())), new WindowNode.Frame(WindowFrameType.RANGE, UNBOUNDED_PRECEDING, Optional.of(startValue1), CURRENT_ROW, Optional.of(endValue1), Optional.of(startValue1.getName()), Optional.of(endValue2.getName()))), output2, new WindowNode.Function(call(FUNCTION_NAME, FUNCTION_HANDLE, BIGINT, ImmutableList.of(p.variable(input2.getName()))), ImmutableList.of(p.variable(input2.getName())), new WindowNode.Frame(WindowFrameType.RANGE, UNBOUNDED_PRECEDING, Optional.of(startValue2), CURRENT_ROW, Optional.of(endValue2), Optional.of(startValue2.getName()), Optional.of(endValue2.getName())))), hash, p.values(inputs.stream().filter(sourceFilter).collect(toImmutableList()), ImmutableList.of())));
}
Also used : BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) UNBOUNDED_PRECEDING(io.prestosql.spi.sql.expression.Types.FrameBoundType.UNBOUNDED_PRECEDING) Test(org.testng.annotations.Test) SortOrder(io.prestosql.spi.block.SortOrder) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) PlanMatchPattern.windowFrame(io.prestosql.sql.planner.assertions.PlanMatchPattern.windowFrame) ImmutableList(com.google.common.collect.ImmutableList) Expressions.call(io.prestosql.sql.relational.Expressions.call) OrderingScheme(io.prestosql.spi.plan.OrderingScheme) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) ExpectedValueProvider(io.prestosql.sql.planner.assertions.ExpectedValueProvider) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.window(io.prestosql.sql.planner.assertions.PlanMatchPattern.window) Symbol(io.prestosql.spi.plan.Symbol) ImmutableSet(com.google.common.collect.ImmutableSet) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) PlanMatchPattern.strictProject(io.prestosql.sql.planner.assertions.PlanMatchPattern.strictProject) Predicate(java.util.function.Predicate) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FunctionHandle(io.prestosql.spi.function.FunctionHandle) List(java.util.List) WindowNode(io.prestosql.spi.plan.WindowNode) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) CURRENT_ROW(io.prestosql.spi.sql.expression.Types.FrameBoundType.CURRENT_ROW) OrderingScheme(io.prestosql.spi.plan.OrderingScheme) WindowNode(io.prestosql.spi.plan.WindowNode) PlanMatchPattern.windowFrame(io.prestosql.sql.planner.assertions.PlanMatchPattern.windowFrame) Symbol(io.prestosql.spi.plan.Symbol)

Example 22 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class TestJoinEnumerator method createContext.

private Rule.Context createContext() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    Map<Symbol, Type> symbols = new HashMap<>();
    symbols.put(new Symbol("A1"), BIGINT);
    symbols.put(new Symbol("B1"), BIGINT);
    PlanSymbolAllocator planSymbolAllocator = new PlanSymbolAllocator(symbols);
    CachingStatsProvider statsProvider = new CachingStatsProvider(queryRunner.getStatsCalculator(), Optional.empty(), noLookup(), queryRunner.getDefaultSession(), planSymbolAllocator.getTypes());
    CachingCostProvider costProvider = new CachingCostProvider(queryRunner.getCostCalculator(), statsProvider, Optional.empty(), queryRunner.getDefaultSession(), planSymbolAllocator.getTypes());
    return new Rule.Context() {

        @Override
        public Lookup getLookup() {
            return noLookup();
        }

        @Override
        public PlanNodeIdAllocator getIdAllocator() {
            return planNodeIdAllocator;
        }

        @Override
        public PlanSymbolAllocator getSymbolAllocator() {
            return planSymbolAllocator;
        }

        @Override
        public Session getSession() {
            return queryRunner.getDefaultSession();
        }

        @Override
        public StatsProvider getStatsProvider() {
            return statsProvider;
        }

        @Override
        public CostProvider getCostProvider() {
            return costProvider;
        }

        @Override
        public void checkTimeoutNotExhausted() {
        }

        @Override
        public WarningCollector getWarningCollector() {
            return WarningCollector.NOOP;
        }
    };
}
Also used : Type(io.prestosql.spi.type.Type) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) CachingCostProvider(io.prestosql.cost.CachingCostProvider) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator)

Example 23 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class TestPruneLimitColumns method buildProjectedLimit.

private ProjectNode buildProjectedLimit(PlanBuilder planBuilder, Predicate<Symbol> projectionFilter) {
    Symbol a = planBuilder.symbol("a");
    Symbol b = planBuilder.symbol("b");
    return planBuilder.project(Assignments.copyOf(Stream.of(a, b).filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> planBuilder.variable(v.getName(), BIGINT)))), planBuilder.limit(1, planBuilder.values(a, b)));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) PlanMatchPattern.strictProject(io.prestosql.sql.planner.assertions.PlanMatchPattern.strictProject) Predicate(java.util.function.Predicate) Test(org.testng.annotations.Test) ProjectNode(io.prestosql.spi.plan.ProjectNode) Collectors(java.util.stream.Collectors) PlanMatchPattern.limit(io.prestosql.sql.planner.assertions.PlanMatchPattern.limit) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) Symbol(io.prestosql.spi.plan.Symbol)

Example 24 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class TestPruneOffsetColumns method buildProjectedOffset.

private ProjectNode buildProjectedOffset(PlanBuilder planBuilder, Predicate<Symbol> projectionFilter) {
    Symbol a = planBuilder.symbol("a");
    Symbol b = planBuilder.symbol("b");
    return planBuilder.project(Assignments.copyOf(Stream.of(a, b).filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> planBuilder.variable(v.getName())))), planBuilder.offset(1, planBuilder.values(a, b)));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) PlanMatchPattern.strictProject(io.prestosql.sql.planner.assertions.PlanMatchPattern.strictProject) Predicate(java.util.function.Predicate) Test(org.testng.annotations.Test) ProjectNode(io.prestosql.spi.plan.ProjectNode) Collectors(java.util.stream.Collectors) PlanMatchPattern.offset(io.prestosql.sql.planner.assertions.PlanMatchPattern.offset) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) Stream(java.util.stream.Stream) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) Symbol(io.prestosql.spi.plan.Symbol)

Example 25 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class TestPruneOrderByInAggregation method buildAggregation.

private AggregationNode buildAggregation(PlanBuilder planBuilder) {
    Symbol avg = planBuilder.symbol("avg");
    Symbol arrayAgg = planBuilder.symbol("array_agg");
    Symbol input = planBuilder.symbol("input");
    Symbol key = planBuilder.symbol("key");
    Symbol keyHash = planBuilder.symbol("keyHash");
    Symbol mask = planBuilder.symbol("mask");
    List<Symbol> sourceSymbols = ImmutableList.of(input, key, keyHash, mask);
    return planBuilder.aggregation(aggregationBuilder -> aggregationBuilder.singleGroupingSet(key).addAggregation(avg, PlanBuilder.expression("avg(input order by input)"), ImmutableList.of(BIGINT), mask).addAggregation(arrayAgg, PlanBuilder.expression("array_agg(input order by input)"), ImmutableList.of(BIGINT), mask).hashSymbol(keyHash).source(planBuilder.values(sourceSymbols, ImmutableList.of())));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol)

Aggregations

Symbol (io.prestosql.spi.plan.Symbol)352 Test (org.testng.annotations.Test)116 ImmutableList (com.google.common.collect.ImmutableList)115 PlanNode (io.prestosql.spi.plan.PlanNode)110 ImmutableMap (com.google.common.collect.ImmutableMap)104 RowExpression (io.prestosql.spi.relation.RowExpression)101 Optional (java.util.Optional)92 Map (java.util.Map)85 Expression (io.prestosql.sql.tree.Expression)79 ProjectNode (io.prestosql.spi.plan.ProjectNode)75 Type (io.prestosql.spi.type.Type)72 JoinNode (io.prestosql.spi.plan.JoinNode)69 List (java.util.List)69 Assignments (io.prestosql.spi.plan.Assignments)65 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)63 AggregationNode (io.prestosql.spi.plan.AggregationNode)60 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)57 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)57 HashMap (java.util.HashMap)57 TableScanNode (io.prestosql.spi.plan.TableScanNode)56