use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class WindowMatcher 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());
WindowNode windowNode = (WindowNode) node;
if (!prePartitionedInputs.map(expectedInputs -> expectedInputs.stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableSet()).equals(windowNode.getPrePartitionedInputs().stream().map(VariableReferenceExpression::getName).map(Symbol::new).collect(toImmutableSet()))).orElse(true)) {
return NO_MATCH;
}
if (!specification.map(expectedSpecification -> matchSpecification(windowNode.getSpecification(), expectedSpecification.getExpectedValue(symbolAliases))).orElse(true)) {
return NO_MATCH;
}
if (!preSortedOrderPrefix.map(Integer.valueOf(windowNode.getPreSortedOrderPrefix())::equals).orElse(true)) {
return NO_MATCH;
}
if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(alias -> alias.toSymbol(symbolAliases)).map(Symbol::getName).equals(windowNode.getHashVariable().map(VariableReferenceExpression::getName))).orElse(true)) {
return NO_MATCH;
}
/*
* Window functions produce a symbol (the result of the function call) that we might
* want to bind to an alias so we can reference it further up the tree. As such,
* they need to be matched with an Alias matcher so we can bind the symbol if desired.
*/
return match();
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class AggregationMatcher 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());
AggregationNode aggregationNode = (AggregationNode) node;
if (groupId.isPresent() != aggregationNode.getGroupIdVariable().isPresent()) {
return NO_MATCH;
}
if (!matches(groupingSets.getGroupingKeys(), aggregationNode.getGroupingKeys(), symbolAliases)) {
return NO_MATCH;
}
if (groupingSets.getGroupingSetCount() != aggregationNode.getGroupingSetCount()) {
return NO_MATCH;
}
if (!groupingSets.getGlobalGroupingSets().equals(aggregationNode.getGlobalGroupingSets())) {
return NO_MATCH;
}
List<VariableReferenceExpression> aggregationsWithMask = aggregationNode.getAggregations().entrySet().stream().filter(entry -> entry.getValue().getMask().isPresent()).map(Map.Entry::getKey).collect(Collectors.toList());
if (aggregationsWithMask.size() != masks.keySet().size()) {
return NO_MATCH;
}
for (VariableReferenceExpression variable : aggregationsWithMask) {
if (!masks.keySet().contains(new Symbol(variable.getName()))) {
return NO_MATCH;
}
}
if (step != aggregationNode.getStep()) {
return NO_MATCH;
}
if (!matches(preGroupedSymbols, aggregationNode.getPreGroupedVariables(), symbolAliases)) {
return NO_MATCH;
}
return match();
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class RowNumberMatcher 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());
RowNumberNode rowNumberNode = (RowNumberNode) node;
if (!partitionBy.map(expectedPartitionBy -> expectedPartitionBy.stream().map(alias -> alias.toSymbol(symbolAliases)).map(Symbol::getName).collect(toImmutableList()).equals(rowNumberNode.getPartitionBy().stream().map(VariableReferenceExpression::getName).collect(toImmutableList()))).orElse(true)) {
return NO_MATCH;
}
if (!maxRowCountPerPartition.map(expectedMaxRowCountPerPartition -> expectedMaxRowCountPerPartition.equals(rowNumberNode.getMaxRowCountPerPartition())).orElse(true)) {
return NO_MATCH;
}
if (!rowNumberSymbol.map(expectedRowNumberSymbol -> expectedRowNumberSymbol.toSymbol(symbolAliases).getName().equals(rowNumberNode.getRowNumberVariable().getName())).orElse(true)) {
return NO_MATCH;
}
if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(symbolAlias -> symbolAlias.toSymbol(symbolAliases)).map(Symbol::getName).equals(rowNumberNode.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 ColumnReference method getAssignedVariable.
@Override
public Optional<VariableReferenceExpression> getAssignedVariable(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
TableHandle tableHandle;
Map<VariableReferenceExpression, ColumnHandle> assignments;
if (node instanceof TableScanNode) {
TableScanNode tableScanNode = (TableScanNode) node;
tableHandle = tableScanNode.getTable();
assignments = tableScanNode.getAssignments();
} else if (node instanceof IndexSourceNode) {
IndexSourceNode indexSourceNode = (IndexSourceNode) node;
tableHandle = indexSourceNode.getTableHandle();
assignments = indexSourceNode.getAssignments();
} else {
return Optional.empty();
}
TableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
String actualTableName = tableMetadata.getTable().getTableName();
// Wrong table -> doesn't match.
if (!tableName.equalsIgnoreCase(actualTableName)) {
return Optional.empty();
}
Optional<ColumnHandle> columnHandle = getColumnHandle(tableHandle, session, metadata);
checkState(columnHandle.isPresent(), format("Table %s doesn't have column %s. Typo in test?", tableName, columnName));
return getAssignedVariable(assignments, columnHandle.get());
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class DynamicFilterMatcher method match.
private boolean match() {
checkState(symbolAliases != null, "symbolAliases is null");
// both nodes must be provided to do the matching
if (filterNode == null || joinNode == null) {
return true;
}
Map<String, VariableReferenceExpression> idToProbeSymbolMap = extractDynamicFilters(filterNode.getPredicate()).getDynamicConjuncts().stream().collect(toImmutableMap(DynamicFilters.DynamicFilterPlaceholder::getId, filter -> (VariableReferenceExpression) filter.getInput()));
Map<String, VariableReferenceExpression> idToBuildSymbolMap = joinNode.getDynamicFilters();
if (idToProbeSymbolMap == null) {
return false;
}
if (idToProbeSymbolMap.size() != expectedDynamicFilters.size()) {
return false;
}
Map<Symbol, Symbol> actual = new HashMap<>();
for (Map.Entry<String, VariableReferenceExpression> idToProbeSymbol : idToProbeSymbolMap.entrySet()) {
String id = idToProbeSymbol.getKey();
VariableReferenceExpression probe = idToProbeSymbol.getValue();
VariableReferenceExpression build = idToBuildSymbolMap.get(id);
if (build == null) {
return false;
}
actual.put(new Symbol(probe.getName()), new Symbol(build.getName()));
}
Map<Symbol, Symbol> expected = expectedDynamicFilters.entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().toSymbol(symbolAliases), entry -> entry.getValue().toSymbol(symbolAliases)));
return expected.equals(actual);
}
Aggregations