use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestDruidQueryBase method project.
protected ProjectNode project(PlanBuilder planBuilder, PlanNode source, List<String> columnNames) {
Map<String, VariableReferenceExpression> incomingColumns = source.getOutputVariables().stream().collect(toMap(VariableReferenceExpression::getName, identity()));
Assignments.Builder assignmentsBuilder = Assignments.builder();
columnNames.forEach(columnName -> {
VariableReferenceExpression variable = requireNonNull(incomingColumns.get(columnName), "Couldn't find the incoming column " + columnName);
assignmentsBuilder.put(variable, variable);
});
return planBuilder.project(assignmentsBuilder.build(), source);
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestDruidPlanOptimizer method testUnionAll.
@Test
public void testUnionAll() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
PlanVariableAllocator variableAllocator = new PlanVariableAllocator();
AggregationNode aggregationOne = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableOne, city, fare), variableAllocator, ImmutableList.of(city), fare);
AggregationNode aggregationTwo = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableTwo, city, fare), variableAllocator, ImmutableList.of(city), fare);
VariableReferenceExpression groupByColumn = variableAllocator.newVariable(city.getColumnName(), city.getColumnType());
VariableReferenceExpression sumColumn = variableAllocator.newVariable(fare.getColumnName(), fare.getColumnType());
PlanNode originalPlan = new UnionNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), ImmutableList.of(aggregationOne, aggregationTwo), ImmutableList.of(groupByColumn, sumColumn), ImmutableMap.of(groupByColumn, Stream.concat(aggregationOne.getGroupingKeys().stream(), aggregationTwo.getGroupingKeys().stream()).collect(toImmutableList()), sumColumn, ImmutableList.of(Iterables.getOnlyElement(aggregationOne.getAggregations().keySet()), Iterables.getOnlyElement(aggregationTwo.getAggregations().keySet()))));
PlanNode optimizedPlan = getOptimizedPlan(planBuilder, originalPlan);
PlanMatchPattern tableScanMatcherOne = DruidTableScanMatcher.match(druidTableOne.getTableName(), "SELECT \"city\", sum(fare) FROM \"realtimeOnly\" GROUP BY \"city\"");
PlanMatchPattern tableScanMatcherTwo = DruidTableScanMatcher.match(druidTableTwo.getTableName(), "SELECT \"city\", sum(fare) FROM \"hybrid\" GROUP BY \"city\"");
assertPlanMatch(optimizedPlan, PlanMatchPattern.union(tableScanMatcherOne, tableScanMatcherTwo), typeProvider);
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression 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.relation.VariableReferenceExpression in project presto by prestodb.
the class WindowFunctionMatcher method getAssignedVariable.
@Override
public Optional<VariableReferenceExpression> getAssignedVariable(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
Optional<VariableReferenceExpression> result = Optional.empty();
if (!(node instanceof WindowNode)) {
return result;
}
WindowNode windowNode = (WindowNode) node;
FunctionCall expectedCall = callMaker.getExpectedValue(symbolAliases);
Optional<WindowNode.Frame> expectedFrame = frameMaker.map(maker -> maker.getExpectedValue(symbolAliases));
List<VariableReferenceExpression> matchedOutputs = windowNode.getWindowFunctions().entrySet().stream().filter(assignment -> {
if (!expectedCall.getName().equals(QualifiedName.of(metadata.getFunctionAndTypeManager().getFunctionMetadata(assignment.getValue().getFunctionCall().getFunctionHandle()).getName().getObjectName()))) {
return false;
}
if (!functionHandle.map(assignment.getValue().getFunctionHandle()::equals).orElse(true)) {
return false;
}
if (!expectedFrame.map(assignment.getValue().getFrame()::equals).orElse(true)) {
return false;
}
List<Expression> expectedExpressions = expectedCall.getArguments();
List<RowExpression> actualExpressions = assignment.getValue().getFunctionCall().getArguments();
if (expectedExpressions.size() != actualExpressions.size()) {
return false;
}
for (int i = 0; i < expectedExpressions.size(); i++) {
Expression expectedExpression = expectedExpressions.get(i);
RowExpression actualExpression = actualExpressions.get(i);
if (!isExpression(actualExpression)) {
SymbolAliases.Builder builder = SymbolAliases.builder();
ImmutableSet.copyOf(VariablesExtractor.extractAllSymbols(expectedExpression)).forEach(symbol -> builder.put(symbol.getName(), symbol.toSymbolReference()));
if (!new RowExpressionVerifier(builder.build(), metadata, session).process(expectedExpression, actualExpression)) {
return false;
}
} else {
if (!expectedExpression.equals(castToExpression(actualExpression))) {
return false;
}
}
}
return true;
}).map(Map.Entry::getKey).collect(toImmutableList());
checkState(matchedOutputs.size() <= 1, "Ambiguous function calls in %s", windowNode);
if (matchedOutputs.isEmpty()) {
return Optional.empty();
}
return Optional.of(matchedOutputs.get(0));
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestDetermineJoinDistributionType method testChoosesLeftWhenCriteriaEmpty.
@Test
public void testChoosesLeftWhenCriteriaEmpty() {
int aRows = 1_000__00;
int bRows = 1_0;
assertDetermineJoinDistributionType(new CostComparator(75, 10, 15)).setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "1PB").overrideStats("valuesA", PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "A1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 100))).build()).overrideStats("valuesB", PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "B1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 100))).build()).on(p -> p.join(RIGHT, p.values(new PlanNodeId("valuesA"), aRows, p.variable("A1", BIGINT)), p.values(new PlanNodeId("valuesB"), bRows, p.variable("B1", BIGINT)), ImmutableList.of(), ImmutableList.of(p.variable("A1", BIGINT), p.variable("B1", BIGINT)), Optional.empty())).matches(join(LEFT, ImmutableList.of(), Optional.empty(), Optional.of(REPLICATED), values(ImmutableMap.of("B1", 0)), values(ImmutableMap.of("A1", 0))));
}
Aggregations