use of io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch in project trino by trinodb.
the class PatternRecognitionMatcher 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());
PatternRecognitionNode patternRecognitionNode = (PatternRecognitionNode) node;
boolean specificationMatches = specification.map(expected -> expected.getExpectedValue(symbolAliases).equals(patternRecognitionNode.getSpecification())).orElse(true);
if (!specificationMatches) {
return NO_MATCH;
}
if (frame.isPresent()) {
if (patternRecognitionNode.getCommonBaseFrame().isEmpty()) {
return NO_MATCH;
}
if (!frame.get().getExpectedValue(symbolAliases).equals(patternRecognitionNode.getCommonBaseFrame().get())) {
return NO_MATCH;
}
}
if (rowsPerMatch != patternRecognitionNode.getRowsPerMatch()) {
return NO_MATCH;
}
if (!skipToLabel.equals(patternRecognitionNode.getSkipToLabel())) {
return NO_MATCH;
}
if (skipToPosition != patternRecognitionNode.getSkipToPosition()) {
return NO_MATCH;
}
if (initial != patternRecognitionNode.isInitial()) {
return NO_MATCH;
}
if (!pattern.equals(patternRecognitionNode.getPattern())) {
return NO_MATCH;
}
if (!subsets.equals(patternRecognitionNode.getSubsets())) {
return NO_MATCH;
}
if (variableDefinitions.size() != patternRecognitionNode.getVariableDefinitions().size()) {
return NO_MATCH;
}
for (Map.Entry<IrLabel, ExpressionAndValuePointers> entry : variableDefinitions.entrySet()) {
IrLabel name = entry.getKey();
ExpressionAndValuePointers actual = patternRecognitionNode.getVariableDefinitions().get(name);
if (actual == null) {
return NO_MATCH;
}
ExpressionAndValuePointers expected = entry.getValue();
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
if (!ExpressionAndValuePointersEquivalence.equivalent(actual, expected, (actualSymbol, expectedSymbol) -> verifier.process(actualSymbol.toSymbolReference(), expectedSymbol.toSymbolReference()))) {
return NO_MATCH;
}
}
return match();
}
Aggregations