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)));
}
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);
}
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));
}
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)));
}
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);
}
}
Aggregations