use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TopNRowNumberMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
TopNRowNumberNode topNRowNumberNode = (TopNRowNumberNode) node;
if (!specification.map(expectedSpecification -> matchSpecification(topNRowNumberNode.getSpecification(), expectedSpecification.getExpectedValue(symbolAliases))).orElse(true)) {
return NO_MATCH;
}
if (!rowNumberSymbol.map(expectedRowNumberSymbol -> expectedRowNumberSymbol.toSymbol(symbolAliases).getName().equals(topNRowNumberNode.getRowNumberVariable().getName())).orElse(true)) {
return NO_MATCH;
}
if (!maxRowCountPerPartition.map(expectedMaxRowCountPerPartition -> expectedMaxRowCountPerPartition.equals(topNRowNumberNode.getMaxRowCountPerPartition())).orElse(true)) {
return NO_MATCH;
}
if (!partial.map(expectedPartial -> expectedPartial.equals(topNRowNumberNode.isPartial())).orElse(true)) {
return NO_MATCH;
}
if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(symbolAlias -> symbolAlias.toSymbol(symbolAliases)).map(Symbol::getName).equals(topNRowNumberNode.getHashVariable().map(VariableReferenceExpression::getName))).orElse(true)) {
return NO_MATCH;
}
return match();
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class ValuesMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
ValuesNode valuesNode = (ValuesNode) node;
if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows().stream().map(rowExpressions -> rowExpressions.stream().map(rowExpression -> {
if (isExpression(rowExpression)) {
return castToExpression(rowExpression);
}
ConstantExpression expression = (ConstantExpression) rowExpression;
if (expression.getType().getJavaType() == boolean.class) {
return new BooleanLiteral(String.valueOf(expression.getValue()));
}
if (expression.getType().getJavaType() == long.class) {
return new LongLiteral(String.valueOf(expression.getValue()));
}
if (expression.getType().getJavaType() == double.class) {
return new DoubleLiteral(String.valueOf(expression.getValue()));
}
if (expression.getType().getJavaType() == Slice.class) {
return new StringLiteral(((Slice) expression.getValue()).toStringUtf8());
}
return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
}).collect(toImmutableList())).collect(toImmutableSet()))).orElse(true)) {
return NO_MATCH;
}
return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> createSymbolReference(valuesNode.getOutputVariables().get(index)))).build());
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestEliminateCrossJoins method testJoinOrder.
@Test
public void testJoinOrder() {
PlanNode plan = joinNode(joinNode(values(variable("a")), values(variable("b"))), values(variable("c")), variable("a"), variable("c"), variable("c"), variable("b"));
JoinGraph joinGraph = getOnlyElement(JoinGraph.buildFrom(plan));
assertEquals(getJoinOrder(joinGraph), ImmutableList.of(0, 2, 1));
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestEliminateCrossJoins method testGiveUpOnNonIdentityProjections.
@Test
public void testGiveUpOnNonIdentityProjections() {
PlanNode plan = joinNode(projectNode(joinNode(values(variable("a1")), values(variable("b"))), variable("a2"), new ArithmeticUnaryExpression(MINUS, new SymbolReference("a1"))), values(variable("c")), variable("a2"), variable("c"), variable("c"), variable("b"));
assertEquals(JoinGraph.buildFrom(plan).size(), 2);
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestMemo method testInsertNode.
/*
From: X -> Z
To: X -> Y -> Z
*/
@Test
public void testInsertNode() {
PlanNode z = node();
PlanNode x = node(z);
Memo memo = new Memo(idAllocator, x);
assertEquals(memo.getGroupCount(), 2);
int zGroup = getChildGroup(memo, memo.getRootGroup());
PlanNode y = node(memo.getNode(zGroup));
memo.replace(zGroup, y, "rule");
assertEquals(memo.getGroupCount(), 3);
assertMatchesStructure(memo.extract(), node(x.getId(), node(y.getId(), node(z.getId()))));
}
Aggregations