Search in sources :

Example 1 with OrderingScheme

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

the class LimitMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node));
    if (!((LimitNode) node).isWithTies()) {
        return match();
    }
    OrderingScheme tiesResolvingScheme = ((LimitNode) node).getTiesResolvingScheme().get();
    if (orderingSchemeMatches(tiesResolvers, tiesResolvingScheme, symbolAliases)) {
        return match();
    }
    return NO_MATCH;
}
Also used : OrderingScheme(io.prestosql.spi.plan.OrderingScheme)

Example 2 with OrderingScheme

use of io.prestosql.spi.plan.OrderingScheme 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 3 with OrderingScheme

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

the class TestEffectivePredicateExtractor method testWindow.

@Test
public void testWindow() {
    PlanNode node = new WindowNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), new WindowNode.Specification(ImmutableList.of(A), Optional.of(new OrderingScheme(ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)))), ImmutableMap.of(), Optional.empty(), ImmutableSet.of(), 0);
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // Pass through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
Also used : WindowNode(io.prestosql.spi.plan.WindowNode) OrderingScheme(io.prestosql.spi.plan.OrderingScheme) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 4 with OrderingScheme

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

the class TestEffectivePredicateExtractor method testTopN.

@Test
public void testTopN() {
    PlanNode node = new TopNNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, new OrderingScheme(ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)), TopNNode.Step.PARTIAL);
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // Pass through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
Also used : OrderingScheme(io.prestosql.spi.plan.OrderingScheme) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) TopNNode(io.prestosql.spi.plan.TopNNode) Test(org.testng.annotations.Test)

Example 5 with OrderingScheme

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

the class TestBaseBaseJdbcQueryGenerator method testWindowFunctionWithOrderBy.

@Test
public void testWindowFunctionWithOrderBy() {
    PlanNode scanNode = buildPlan(planBuilder -> tableScan(planBuilder, jdbcTable, regionId, city, fare, amount));
    testJQL(planBuilder -> planBuilder.window(new WindowNode.Specification(ImmutableList.of(), Optional.of(new OrderingScheme(ImmutableList.of(symbol("fare")), ImmutableMap.of(symbol("fare"), SortOrder.ASC_NULLS_FIRST)))), ImmutableMap.of(symbol("amount_out"), new WindowNode.Function(call("min", metadata.getFunctionAndTypeManager().lookupFunction("min", fromTypes(BIGINT)), BIGINT, ImmutableList.of(new VariableReferenceExpression("amount", types.get(symbol("amount"))))), ImmutableList.of(new VariableReferenceExpression("amount", types.get(symbol("amount")))), new WindowNode.Frame(Types.WindowFrameType.RANGE, Types.FrameBoundType.UNBOUNDED_PRECEDING, Optional.empty(), Types.FrameBoundType.CURRENT_ROW, Optional.empty(), Optional.empty(), Optional.empty()))), symbol("city"), scanNode), "SELECT regionid, city, fare, amount, min(amount) OVER ( ORDER BY fare ASC NULLS FIRST RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS amount_out FROM (SELECT regionid, city, fare, amount FROM 'table') hetu_table_1");
}
Also used : OrderingScheme(io.prestosql.spi.plan.OrderingScheme) WindowNode(io.prestosql.spi.plan.WindowNode) PlanNode(io.prestosql.spi.plan.PlanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test)

Aggregations

OrderingScheme (io.prestosql.spi.plan.OrderingScheme)13 PlanNode (io.prestosql.spi.plan.PlanNode)8 WindowNode (io.prestosql.spi.plan.WindowNode)8 Symbol (io.prestosql.spi.plan.Symbol)7 RowExpression (io.prestosql.spi.relation.RowExpression)7 Expression (io.prestosql.sql.tree.Expression)7 Test (org.testng.annotations.Test)7 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)6 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)6 SortOrder (io.prestosql.spi.block.SortOrder)5 CallExpression (io.prestosql.spi.relation.CallExpression)4 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Iterables (com.google.common.collect.Iterables)2 Sets (com.google.common.collect.Sets)2