Search in sources :

Example 6 with ProjectNode

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

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

the class TestTypeValidator method testInvalidProject.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'expr(_[0-9]+)?' is expected to be bigint, but the actual type is integer")
public void testInvalidProject() {
    Expression expression1 = new Cast(toSymbolReference(columnB), StandardTypes.INTEGER);
    Expression expression2 = new Cast(toSymbolReference(columnA), StandardTypes.INTEGER);
    Assignments assignments = Assignments.builder().put(planSymbolAllocator.newSymbol(expression1, BIGINT), // should be INTEGER
    castToRowExpression(expression1)).put(planSymbolAllocator.newSymbol(expression1, INTEGER), castToRowExpression(expression2)).build();
    PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
    assertTypesValid(node);
}
Also used : Cast(io.prestosql.sql.tree.Cast) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 8 with ProjectNode

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

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

the class TestEffectivePredicateExtractor method testProject.

@Test
public void testProject() {
    PlanNode node = new ProjectNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), assignment(D, AE, E, CE));
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // Rewrite in terms of project output symbols
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(lessThan(DE, bigintLiteral(10)), equals(DE, EE)));
}
Also used : 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) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 10 with ProjectNode

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

the class SqlQueryExecution method findMappingFromPlan.

private void findMappingFromPlan(Map<String, Set<String>> mapping, PlanNode sourceNode) {
    if (sourceNode != null && sourceNode instanceof ProjectNode) {
        ProjectNode projectNode = (ProjectNode) sourceNode;
        Map<Symbol, RowExpression> assignments = projectNode.getAssignments().getMap();
        for (Symbol symbol : assignments.keySet()) {
            if (mapping.containsKey(symbol.getName())) {
                Set<String> sets = mapping.get(symbol.getName());
                RowExpression expression = assignments.get(symbol);
                if (expression instanceof VariableReferenceExpression) {
                    sets.add(((VariableReferenceExpression) expression).getName());
                } else {
                    sets.add(expression.toString());
                }
            } else {
                for (Map.Entry<String, Set<String>> entry : mapping.entrySet()) {
                    if (entry.getValue().contains(symbol.getName())) {
                        RowExpression expression = assignments.get(symbol);
                        if (expression instanceof VariableReferenceExpression) {
                            entry.getValue().add(((VariableReferenceExpression) expression).getName());
                        } else {
                            entry.getValue().add(expression.toString());
                        }
                    }
                }
            }
        }
    }
    for (PlanNode planNode : sourceNode.getSources()) {
        findMappingFromPlan(mapping, planNode);
    }
}
Also used : Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) ProjectNode(io.prestosql.spi.plan.ProjectNode) Map(java.util.Map) StateMap(io.prestosql.spi.statestore.StateMap) HashMap(java.util.HashMap)

Aggregations

ProjectNode (io.prestosql.spi.plan.ProjectNode)79 Symbol (io.prestosql.spi.plan.Symbol)56 Assignments (io.prestosql.spi.plan.Assignments)47 PlanNode (io.prestosql.spi.plan.PlanNode)40 RowExpression (io.prestosql.spi.relation.RowExpression)30 Expression (io.prestosql.sql.tree.Expression)30 ImmutableList (com.google.common.collect.ImmutableList)29 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)27 ImmutableMap (com.google.common.collect.ImmutableMap)25 AggregationNode (io.prestosql.spi.plan.AggregationNode)25 Map (java.util.Map)24 FilterNode (io.prestosql.spi.plan.FilterNode)22 TableScanNode (io.prestosql.spi.plan.TableScanNode)21 Cast (io.prestosql.sql.tree.Cast)20 List (java.util.List)19 CallExpression (io.prestosql.spi.relation.CallExpression)18 HashMap (java.util.HashMap)18 Type (io.prestosql.spi.type.Type)17 Test (org.testng.annotations.Test)17 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)16