Search in sources :

Example 21 with ValuesNode

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

the class TestJoinNodeFlattener method testDoesNotConvertNestedOuterJoins.

@Test
public void testDoesNotConvertNestedOuterJoins() {
    PlanBuilder p = planBuilder();
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    Symbol c1 = p.symbol("C1");
    JoinNode leftJoin = p.join(LEFT, p.values(a1), p.values(b1), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1), Optional.empty());
    ValuesNode valuesC = p.values(c1);
    JoinNode joinNode = p.join(INNER, leftJoin, valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1, c1), Optional.empty());
    MultiJoinNode expected = MultiJoinNode.builder().setSources(leftJoin, valuesC).setFilter(createEqualsExpression(a1, c1, p.getTypes())).setOutputSymbols(a1, b1, c1).setLogicalRowExpressions(logicalRowExpressions).build();
    assertEquals(toMultiJoinNode(joinNode, noLookup(), DEFAULT_JOIN_LIMIT, queryRunner.getMetadata(), p.getTypes(), logicalRowExpressions), expected);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) Symbol(io.prestosql.spi.plan.Symbol) MultiJoinNode.toMultiJoinNode(io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) MultiJoinNode(io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode.toMultiJoinNode(io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) MultiJoinNode(io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) Test(org.testng.annotations.Test)

Example 22 with ValuesNode

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

the class TestJoinNodeFlattener method testCombinesCriteriaAndFilters.

@Test
public void testCombinesCriteriaAndFilters() {
    PlanBuilder p = planBuilder();
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    Symbol b2 = p.symbol("B2");
    Symbol c1 = p.symbol("C1");
    Symbol c2 = p.symbol("C2");
    ValuesNode valuesA = p.values(a1);
    ValuesNode valuesB = p.values(b1, b2);
    ValuesNode valuesC = p.values(c1, c2);
    RowExpression bcFilter = LogicalRowExpressions.and(p.comparison(OperatorType.GREATER_THAN, p.variable(c2.getName()), constant(0L, BIGINT)), p.comparison(OperatorType.NOT_EQUAL, p.variable(c2.getName()), constant(7L, BIGINT)), p.comparison(OperatorType.GREATER_THAN, p.variable(b2.getName()), p.variable(c2.getName())));
    RowExpression abcFilter = p.comparison(OperatorType.LESS_THAN, p.binaryOperation(OperatorType.ADD, p.variable(a1.getName()), p.variable(c1.getName())), p.variable(b1.getName()));
    JoinNode joinNode = p.join(INNER, valuesA, p.join(INNER, valuesB, valuesC, ImmutableList.of(equiJoinClause(b1, c1)), ImmutableList.of(b1, b2, c1, c2), Optional.of(bcFilter)), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1, b2, c1, c2), Optional.of(abcFilter));
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) Symbol(io.prestosql.spi.plan.Symbol) MultiJoinNode.toMultiJoinNode(io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) MultiJoinNode(io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) RowExpression(io.prestosql.spi.relation.RowExpression) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 23 with ValuesNode

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

the class TestStageStateMachine method createValuesPlan.

private static PlanFragment createValuesPlan() {
    Symbol symbol = new Symbol("column");
    PlanNodeId valuesNodeId = new PlanNodeId("plan");
    PlanFragment planFragment = new PlanFragment(new PlanFragmentId("plan"), new ValuesNode(valuesNodeId, ImmutableList.of(symbol), ImmutableList.of(ImmutableList.of(castToRowExpression(new StringLiteral("foo"))))), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(valuesNodeId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    return planFragment;
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) ValuesNode(io.prestosql.spi.plan.ValuesNode) StringLiteral(io.prestosql.sql.tree.StringLiteral) Symbol(io.prestosql.spi.plan.Symbol) PartitioningScheme(io.prestosql.sql.planner.PartitioningScheme) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) PlanFragment(io.prestosql.sql.planner.PlanFragment)

Example 24 with ValuesNode

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

the class TestEffectivePredicateExtractor method testValues.

@Test
public void testValues() {
    TypeProvider types = TypeProvider.copyOf(ImmutableMap.<Symbol, Type>builder().put(A, BIGINT).put(B, BIGINT).build());
    // one column
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1)), ImmutableList.of(bigintLiteralRowExpression(2)))), types, typeAnalyzer), new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))));
    // one column with null
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1)), ImmutableList.of(bigintLiteralRowExpression(2)), ImmutableList.of(castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString()))))), types, typeAnalyzer), or(new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))), new IsNullPredicate(AE)));
    // all nulls
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString()))))), types, typeAnalyzer), new IsNullPredicate(AE));
    // many rows
    List<List<RowExpression>> rows = IntStream.range(0, 500).mapToObj(TestEffectivePredicateExtractor::bigintLiteralRowExpression).map(ImmutableList::of).collect(toImmutableList());
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), rows), types, typeAnalyzer), new BetweenPredicate(AE, bigintLiteral(0), bigintLiteral(499)));
    // multiple columns
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1), bigintLiteralRowExpression(100)), ImmutableList.of(bigintLiteralRowExpression(2), bigintLiteralRowExpression(200)))), types, typeAnalyzer), and(new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))), new InPredicate(BE, new InListExpression(ImmutableList.of(bigintLiteral(100), bigintLiteral(200))))));
    // multiple columns with null
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1), castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString()))), ImmutableList.of(castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString())), bigintLiteralRowExpression(200)))), types, typeAnalyzer), and(or(new ComparisonExpression(EQUAL, AE, bigintLiteral(1)), new IsNullPredicate(AE)), or(new ComparisonExpression(EQUAL, BE, bigintLiteral(200)), new IsNullPredicate(BE))));
    // non-deterministic
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1), castToRowExpression(new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()))))), types, typeAnalyzer), new ComparisonExpression(EQUAL, AE, bigintLiteral(1)));
    // non-constant
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1)), ImmutableList.of(castToRowExpression(BE)))), types, typeAnalyzer), TRUE_LITERAL);
}
Also used : Cast(io.prestosql.sql.tree.Cast) ValuesNode(io.prestosql.spi.plan.ValuesNode) BetweenPredicate(io.prestosql.sql.tree.BetweenPredicate) Symbol(io.prestosql.spi.plan.Symbol) InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) IsNullPredicate(io.prestosql.sql.tree.IsNullPredicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FunctionCall(io.prestosql.sql.tree.FunctionCall) NullLiteral(io.prestosql.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Example 25 with ValuesNode

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

the class TestDistributedExecutionPlanner method testValuesResume.

@Test
public void testValuesResume() {
    ValuesNode a = values("A");
    ValuesNode b = values("B");
    SubPlan root = makePlan(1, join(a, b), ImmutableList.of());
    planner.plan(root, session, RESUME, 5L, 7);
    assertEquals(a.getResumeSnapshotId().longValue(), 5);
    assertEquals(a.getNextSnapshotId(), 7);
    assertEquals(b.getResumeSnapshotId().longValue(), 5);
    assertEquals(b.getNextSnapshotId(), 7);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) Test(org.testng.annotations.Test)

Aggregations

ValuesNode (io.prestosql.spi.plan.ValuesNode)26 Symbol (io.prestosql.spi.plan.Symbol)16 Test (org.testng.annotations.Test)12 PlanNode (io.prestosql.spi.plan.PlanNode)8 RowExpression (io.prestosql.spi.relation.RowExpression)8 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)6 JoinNode (io.prestosql.spi.plan.JoinNode)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ProjectNode (io.prestosql.spi.plan.ProjectNode)5 MultiJoinNode (io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)5 MultiJoinNode.toMultiJoinNode (io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)5 PlanBuilder (io.prestosql.sql.planner.iterative.rule.test.PlanBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)4 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)4 Session (io.prestosql.Session)3 OutputNode (io.prestosql.sql.planner.plan.OutputNode)3 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)3 Expression (io.prestosql.sql.tree.Expression)3