Skip to content
5 changes: 5 additions & 0 deletions docs/changelog/143210.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
area: ES|QL
issues: []
pr: 143210
summary: Fix unresolved name pattern
type: bug
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public class UnresolvedNamePattern extends UnresolvedNamedExpression {
private final CharacterRunAutomaton automaton;
private final String pattern;
// string representation without backquotes
private final String name;
// Cannot rely on NamedExpression.name: the UnresolvedNamedExpression superclass throws on name()
// and stores "<unresolved>" as the internal name field.
private final String actualName;

public UnresolvedNamePattern(Source source, CharacterRunAutomaton automaton, String patternString, String name) {
super(source, emptyList());
this.automaton = automaton;
this.pattern = patternString;
this.name = name;
this.actualName = name;
}

@Override
Expand All @@ -58,9 +60,10 @@ public boolean match(String string) {
return automaton.run(string);
}

// override because the super class throws
@Override
public String name() {
return name;
return actualName;
}

public String pattern() {
Expand All @@ -74,7 +77,7 @@ public Expression replaceChildren(List<Expression> newChildren) {

@Override
protected NodeInfo<UnresolvedNamePattern> info() {
return NodeInfo.create(this, UnresolvedNamePattern::new, automaton, pattern, name);
return NodeInfo.create(this, UnresolvedNamePattern::new, automaton, pattern, actualName);
}

@Override
Expand All @@ -99,13 +102,13 @@ public Nullability nullable() {

@Override
protected int innerHashCode(boolean ignoreIds) {
return Objects.hash(super.innerHashCode(true), pattern);
return Objects.hash(super.innerHashCode(true), pattern, actualName);
}

@Override
protected boolean innerEquals(Object o, boolean ignoreIds) {
var other = (UnresolvedNamePattern) o;
return super.innerEquals(other, true) && Objects.equals(pattern, other.pattern);
return super.innerEquals(other, true) && Objects.equals(pattern, other.pattern) && Objects.equals(actualName, other.actualName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected UnresolvedNamePattern mutateInstance(UnresolvedNamePattern instance) {
case 0 -> name = randomValueOtherThan(name, () -> randomAlphaOfLength(4));
case 1 -> pattern = randomValueOtherThan(pattern, () -> randomAlphaOfLength(4));
}
return new UnresolvedNamePattern(source, null, name, pattern);
return new UnresolvedNamePattern(source, null, pattern, name);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was switched up as discovered by @ebarlas . This made is that in very much most of cases, the mutation changed the pattern, anyway, and thus we never saw that changes to the name had no effect on equality.

}

@Override
Expand Down