Skip to content

Commit f58d867

Browse files
alex-spiesdavidkyle
authored andcommitted
ESQL: Remove qualifier from attrs (elastic#110581)
In ES|QL's analyzer, we resolve names to field attributes, like some_field in FROM some_idx | KEEP some_field. The Attribute class, being copied from (S)QL, has a name and a qualified name, e.g. some_field and qualifier.some_field. However, we never use the qualifier, so remove it.
1 parent dc3a10a commit f58d867

34 files changed

+251
-356
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Alias.java

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import java.io.IOException;
1818
import java.util.List;
19-
import java.util.Objects;
2019

2120
import static java.util.Collections.singletonList;
2221

@@ -32,7 +31,6 @@ public final class Alias extends NamedExpression {
3231
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(NamedExpression.class, "Alias", Alias::new);
3332

3433
private final Expression child;
35-
private final String qualifier;
3634

3735
/**
3836
* Postpone attribute creation until it is actually created.
@@ -41,21 +39,24 @@ public final class Alias extends NamedExpression {
4139
private Attribute lazyAttribute;
4240

4341
public Alias(Source source, String name, Expression child) {
44-
this(source, name, null, child, null);
42+
this(source, name, child, null);
4543
}
4644

47-
public Alias(Source source, String name, String qualifier, Expression child) {
48-
this(source, name, qualifier, child, null);
45+
public Alias(Source source, String name, Expression child, NameId id) {
46+
this(source, name, child, id, false);
4947
}
5048

51-
public Alias(Source source, String name, String qualifier, Expression child, NameId id) {
52-
this(source, name, qualifier, child, id, false);
53-
}
54-
55-
public Alias(Source source, String name, String qualifier, Expression child, NameId id, boolean synthetic) {
49+
public Alias(Source source, String name, Expression child, NameId id, boolean synthetic) {
5650
super(source, name, singletonList(child), id, synthetic);
5751
this.child = child;
58-
this.qualifier = qualifier;
52+
}
53+
54+
@Deprecated
55+
/**
56+
* Old constructor from when this had a qualifier string. Still needed to not break serialization.
57+
*/
58+
private Alias(Source source, String name, String qualifier, Expression child, NameId id, boolean synthetic) {
59+
this(source, name, child, id, synthetic);
5960
}
6061

6162
public Alias(StreamInput in) throws IOException {
@@ -73,7 +74,8 @@ public Alias(StreamInput in) throws IOException {
7374
public void writeTo(StreamOutput out) throws IOException {
7475
Source.EMPTY.writeTo(out);
7576
out.writeString(name());
76-
out.writeOptionalString(qualifier());
77+
// We used to write the qualifier here. We can still do if needed in the future.
78+
out.writeOptionalString(null);
7779
out.writeNamedWriteable(child());
7880
id().writeTo(out);
7981
out.writeBoolean(synthetic());
@@ -86,30 +88,22 @@ public String getWriteableName() {
8688

8789
@Override
8890
protected NodeInfo<Alias> info() {
89-
return NodeInfo.create(this, Alias::new, name(), qualifier, child, id(), synthetic());
91+
return NodeInfo.create(this, Alias::new, name(), child, id(), synthetic());
9092
}
9193

9294
public Alias replaceChild(Expression child) {
93-
return new Alias(source(), name(), qualifier, child, id(), synthetic());
95+
return new Alias(source(), name(), child, id(), synthetic());
9496
}
9597

9698
@Override
9799
public Alias replaceChildren(List<Expression> newChildren) {
98-
return new Alias(source(), name(), qualifier, newChildren.get(0), id(), synthetic());
100+
return new Alias(source(), name(), newChildren.get(0), id(), synthetic());
99101
}
100102

101103
public Expression child() {
102104
return child;
103105
}
104106

105-
public String qualifier() {
106-
return qualifier;
107-
}
108-
109-
public String qualifiedName() {
110-
return qualifier == null ? name() : qualifier + "." + name();
111-
}
112-
113107
@Override
114108
public Nullability nullable() {
115109
return child.nullable();
@@ -124,8 +118,8 @@ public DataType dataType() {
124118
public Attribute toAttribute() {
125119
if (lazyAttribute == null) {
126120
lazyAttribute = resolved()
127-
? new ReferenceAttribute(source(), name(), dataType(), qualifier, nullable(), id(), synthetic())
128-
: new UnresolvedAttribute(source(), name(), qualifier);
121+
? new ReferenceAttribute(source(), name(), dataType(), nullable(), id(), synthetic())
122+
: new UnresolvedAttribute(source(), name());
129123
}
130124
return lazyAttribute;
131125
}
@@ -146,18 +140,4 @@ public String nodeString() {
146140
public static Expression unwrap(Expression e) {
147141
return e instanceof Alias as ? as.child() : e;
148142
}
149-
150-
@Override
151-
public boolean equals(Object obj) {
152-
if (super.equals(obj) == false) {
153-
return false;
154-
}
155-
Alias other = (Alias) obj;
156-
return Objects.equals(qualifier, other.qualifier);
157-
}
158-
159-
@Override
160-
public int hashCode() {
161-
return Objects.hash(super.hashCode(), qualifier);
162-
}
163143
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Attribute.java

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
package org.elasticsearch.xpack.esql.core.expression;
88

99
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
10-
import org.elasticsearch.core.Tuple;
1110
import org.elasticsearch.xpack.esql.core.tree.Source;
1211
import org.elasticsearch.xpack.esql.core.type.DataType;
1312

1413
import java.util.List;
1514
import java.util.Objects;
1615

1716
import static java.util.Collections.emptyList;
18-
import static org.elasticsearch.xpack.esql.core.util.StringUtils.splitQualifiedIndex;
1917

2018
/**
2119
* {@link Expression}s that can be materialized and describe properties of the derived table.
@@ -35,33 +33,19 @@ public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
3533
return List.of(FieldAttribute.ENTRY, MetadataAttribute.ENTRY, ReferenceAttribute.ENTRY);
3634
}
3735

38-
// empty - such as a top level attribute in SELECT cause
39-
// present - table name or a table name alias
40-
private final String qualifier;
41-
// cluster name in the qualifier (if any)
42-
private final String cluster;
43-
4436
// can the attr be null - typically used in JOINs
4537
private final Nullability nullability;
4638

47-
public Attribute(Source source, String name, String qualifier, NameId id) {
48-
this(source, name, qualifier, Nullability.TRUE, id);
39+
public Attribute(Source source, String name, NameId id) {
40+
this(source, name, Nullability.TRUE, id);
4941
}
5042

51-
public Attribute(Source source, String name, String qualifier, Nullability nullability, NameId id) {
52-
this(source, name, qualifier, nullability, id, false);
43+
public Attribute(Source source, String name, Nullability nullability, NameId id) {
44+
this(source, name, nullability, id, false);
5345
}
5446

55-
public Attribute(Source source, String name, String qualifier, Nullability nullability, NameId id, boolean synthetic) {
47+
public Attribute(Source source, String name, Nullability nullability, NameId id, boolean synthetic) {
5648
super(source, name, emptyList(), id, synthetic);
57-
if (qualifier != null) {
58-
Tuple<String, String> splitQualifier = splitQualifiedIndex(qualifier);
59-
this.cluster = splitQualifier.v1();
60-
this.qualifier = splitQualifier.v2();
61-
} else {
62-
this.cluster = null;
63-
this.qualifier = null;
64-
}
6549
this.nullability = nullability;
6650
}
6751

@@ -70,14 +54,6 @@ public final Expression replaceChildren(List<Expression> newChildren) {
7054
throw new UnsupportedOperationException("this type of node doesn't have any children to replace");
7155
}
7256

73-
public String qualifier() {
74-
return qualifier;
75-
}
76-
77-
public String qualifiedName() {
78-
return qualifier == null ? name() : qualifier + "." + name();
79-
}
80-
8157
@Override
8258
public Nullability nullable() {
8359
return nullability;
@@ -89,42 +65,26 @@ public AttributeSet references() {
8965
}
9066

9167
public Attribute withLocation(Source source) {
92-
return Objects.equals(source(), source) ? this : clone(source, name(), dataType(), qualifier(), nullable(), id(), synthetic());
93-
}
94-
95-
public Attribute withQualifier(String qualifier) {
96-
return Objects.equals(qualifier(), qualifier)
97-
? this
98-
: clone(source(), name(), dataType(), qualifier, nullable(), id(), synthetic());
68+
return Objects.equals(source(), source) ? this : clone(source, name(), dataType(), nullable(), id(), synthetic());
9969
}
10070

10171
public Attribute withName(String name) {
102-
return Objects.equals(name(), name) ? this : clone(source(), name, dataType(), qualifier(), nullable(), id(), synthetic());
72+
return Objects.equals(name(), name) ? this : clone(source(), name, dataType(), nullable(), id(), synthetic());
10373
}
10474

10575
public Attribute withNullability(Nullability nullability) {
106-
return Objects.equals(nullable(), nullability)
107-
? this
108-
: clone(source(), name(), dataType(), qualifier(), nullability, id(), synthetic());
76+
return Objects.equals(nullable(), nullability) ? this : clone(source(), name(), dataType(), nullability, id(), synthetic());
10977
}
11078

11179
public Attribute withId(NameId id) {
112-
return clone(source(), name(), dataType(), qualifier(), nullable(), id, synthetic());
80+
return clone(source(), name(), dataType(), nullable(), id, synthetic());
11381
}
11482

11583
public Attribute withDataType(DataType type) {
116-
return Objects.equals(dataType(), type) ? this : clone(source(), name(), type, qualifier(), nullable(), id(), synthetic());
84+
return Objects.equals(dataType(), type) ? this : clone(source(), name(), type, nullable(), id(), synthetic());
11785
}
11886

119-
protected abstract Attribute clone(
120-
Source source,
121-
String name,
122-
DataType type,
123-
String qualifier,
124-
Nullability nullability,
125-
NameId id,
126-
boolean synthetic
127-
);
87+
protected abstract Attribute clone(Source source, String name, DataType type, Nullability nullability, NameId id, boolean synthetic);
12888

12989
@Override
13090
public Attribute toAttribute() {
@@ -143,27 +103,27 @@ public boolean semanticEquals(Expression other) {
143103

144104
@Override
145105
protected Expression canonicalize() {
146-
return clone(Source.EMPTY, name(), dataType(), qualifier, nullability, id(), synthetic());
106+
return clone(Source.EMPTY, name(), dataType(), nullability, id(), synthetic());
147107
}
148108

149109
@Override
150110
public int hashCode() {
151-
return Objects.hash(super.hashCode(), qualifier, nullability);
111+
return Objects.hash(super.hashCode(), nullability);
152112
}
153113

154114
@Override
155115
public boolean equals(Object obj) {
156116
if (super.equals(obj)) {
157117
Attribute other = (Attribute) obj;
158-
return Objects.equals(qualifier, other.qualifier) && Objects.equals(nullability, other.nullability);
118+
return Objects.equals(nullability, other.nullability);
159119
}
160120

161121
return false;
162122
}
163123

164124
@Override
165125
public String toString() {
166-
return qualifiedName() + "{" + label() + "}" + "#" + id();
126+
return name() + "{" + label() + "}" + "#" + id();
167127
}
168128

169129
@Override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/EmptyAttribute.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class EmptyAttribute extends Attribute {
2323
public EmptyAttribute(Source source) {
24-
super(source, StringUtils.EMPTY, null, null);
24+
super(source, StringUtils.EMPTY, null);
2525
}
2626

2727
@Override
@@ -35,15 +35,7 @@ public String getWriteableName() {
3535
}
3636

3737
@Override
38-
protected Attribute clone(
39-
Source source,
40-
String name,
41-
DataType type,
42-
String qualifier,
43-
Nullability nullability,
44-
NameId id,
45-
boolean synthetic
46-
) {
38+
protected Attribute clone(Source source, String name, DataType type, Nullability nullability, NameId id, boolean synthetic) {
4739
return this;
4840
}
4941

0 commit comments

Comments
 (0)