use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testProject.
@Test
public void testProject() throws Exception {
PlanNode node = new ProjectNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), Assignments.of(D, AE, E, CE));
Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
// Rewrite in terms of project output symbols
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(DE, bigintLiteral(10)), equals(DE, EE)));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testAggregation.
@Test
public void testAggregation() throws Exception {
PlanNode node = new AggregationNode(newId(), filter(baseTableScan, and(equals(AE, DE), equals(BE, EE), equals(CE, FE), lessThan(DE, bigintLiteral(10)), lessThan(CE, DE), greaterThan(AE, bigintLiteral(2)), equals(EE, FE))), ImmutableMap.of(C, fakeFunction("test"), D, fakeFunction("test")), ImmutableMap.of(C, fakeFunctionHandle("test", AGGREGATE), D, fakeFunctionHandle("test", AGGREGATE)), ImmutableMap.of(), ImmutableList.of(ImmutableList.of(A, B, C)), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty());
Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
// Rewrite in terms of group by symbols
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(AE, bigintLiteral(10)), lessThan(BE, AE), greaterThan(AE, bigintLiteral(2)), equals(BE, CE)));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class PlanMatchingVisitor method matchSources.
/*
* This is a little counter-intuitive. Calling matchSources calls
* source.accept, which (eventually) ends up calling into visitPlan
* recursively. Assuming the plan and pattern currently being matched
* actually match each other, eventually you hit the leaf nodes. At that
* point, visitPlan starts by returning the match result for the leaf nodes
* containing the symbol aliases needed by further up.
*
* For the non-leaf nodes, an invocation of matchSources returns a match
* result for a successful match containing the union of all of the symbol
* aliases added by the sources of the node currently being visited.
*
* Visiting that node proceeds by trying to apply the current pattern's
* detailMatches() method to the node being visited. When a match is found,
* visitPlan returns a match result containing the aliases for all of the
* current node's sources, and the aliases for the current node.
*/
private MatchResult matchSources(PlanNode node, PlanMatchingState state) {
List<PlanMatchPattern> sourcePatterns = state.getPatterns();
checkState(node.getSources().size() == sourcePatterns.size(), "Matchers count does not match count of sources");
int i = 0;
SymbolAliases.Builder allSourceAliases = SymbolAliases.builder();
for (PlanNode source : node.getSources()) {
// Match sources to patterns 1:1
MatchResult matchResult = source.accept(this, sourcePatterns.get(i++));
if (!matchResult.isMatch()) {
return NO_MATCH;
}
// Add the per-source aliases to the per-state aliases.
allSourceAliases.putAll(matchResult.getAliases());
}
return match(allSourceAliases.build());
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestMemo method testReplaceSubtree.
/*
From: X -> Y -> Z
To: X -> Y' -> Z'
*/
@Test
public void testReplaceSubtree() throws Exception {
PlanNode plan = node(node(node()));
Memo memo = new Memo(idAllocator, plan);
assertEquals(memo.getGroupCount(), 3);
// replace child of root node with subtree
PlanNode transformed = node(node());
memo.replace(getChildGroup(memo, memo.getRootGroup()), transformed, "rule");
assertEquals(memo.getGroupCount(), 3);
assertMatchesStructure(memo.extract(), node(plan.getId(), transformed));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestTypeValidator method testInvalidWindowFunctionSignature.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidWindowFunctionSignature() throws Exception {
Symbol windowSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
Signature signature = new Signature("sum", FunctionKind.WINDOW, ImmutableList.of(), ImmutableList.of(), // should be DOUBLE
BIGINT.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()), false);
FunctionCall functionCall = new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnC.toSymbolReference()));
WindowNode.Frame frame = new WindowNode.Frame(WindowFrame.Type.RANGE, FrameBound.Type.UNBOUNDED_PRECEDING, Optional.empty(), FrameBound.Type.UNBOUNDED_FOLLOWING, Optional.empty());
WindowNode.Function function = new WindowNode.Function(functionCall, signature, frame);
WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), ImmutableList.of(), ImmutableMap.of());
PlanNode node = new WindowNode(newId(), baseTableScan, specification, ImmutableMap.of(windowSymbol, function), Optional.empty(), ImmutableSet.of(), 0);
assertTypesValid(node);
}
Aggregations