Skip to content

Commit 1da6ea4

Browse files
authored
ESQL: Fix EsqlNodeSubclassTests (#116496)
- Fix EsqlNodeSubclassTests so that they also test the Node subclasses in esql.core. - Fix the re-enabled tests for Field-/Reference-/MetadataAttribute by using the longest public c'tor in their info() method implementations.
1 parent 7b79a52 commit 1da6ea4

File tree

4 files changed

+10
-64
lines changed

4 files changed

+10
-64
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,7 @@ public String getWriteableName() {
174174

175175
@Override
176176
protected NodeInfo<FieldAttribute> info() {
177-
return NodeInfo.create(
178-
this,
179-
FieldAttribute::new,
180-
parentName,
181-
name(),
182-
dataType(),
183-
field,
184-
(String) null,
185-
nullable(),
186-
id(),
187-
synthetic()
188-
);
177+
return NodeInfo.create(this, FieldAttribute::new, parentName, name(), field, nullable(), id(), synthetic());
189178
}
190179

191180
public String parentName() {

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,7 @@ protected String label() {
147147

148148
@Override
149149
protected NodeInfo<? extends Expression> info() {
150-
return NodeInfo.create(
151-
this,
152-
(source, name, dataType, qualifier, nullability, id, synthetic, searchable1) -> new MetadataAttribute(
153-
source,
154-
name,
155-
dataType,
156-
qualifier,
157-
nullability,
158-
id,
159-
synthetic,
160-
searchable1
161-
),
162-
name(),
163-
dataType(),
164-
(String) null,
165-
nullable(),
166-
id(),
167-
synthetic(),
168-
searchable
169-
);
150+
return NodeInfo.create(this, MetadataAttribute::new, name(), dataType(), nullable(), id(), synthetic(), searchable);
170151
}
171152

172153
public boolean searchable() {

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,7 @@ protected Attribute clone(Source source, String name, DataType dataType, Nullabi
110110

111111
@Override
112112
protected NodeInfo<ReferenceAttribute> info() {
113-
return NodeInfo.create(
114-
this,
115-
(source, name, dataType, qualifier, nullability, id, synthetic) -> new ReferenceAttribute(
116-
source,
117-
name,
118-
dataType,
119-
qualifier,
120-
nullability,
121-
id,
122-
synthetic
123-
),
124-
name(),
125-
dataType(),
126-
(String) null,
127-
nullable(),
128-
id(),
129-
synthetic()
130-
);
113+
return NodeInfo.create(this, ReferenceAttribute::new, name(), dataType(), nullable(), id(), synthetic());
131114
}
132115

133116
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/tree/EsqlNodeSubclassTests.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.elasticsearch.xpack.esql.core.expression.Expression;
2222
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
2323
import org.elasticsearch.xpack.esql.core.expression.Literal;
24-
import org.elasticsearch.xpack.esql.core.expression.MetadataAttribute;
25-
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
2624
import org.elasticsearch.xpack.esql.core.expression.UnresolvedAttribute;
2725
import org.elasticsearch.xpack.esql.core.expression.UnresolvedAttributeTests;
2826
import org.elasticsearch.xpack.esql.core.expression.UnresolvedNamedExpression;
@@ -114,9 +112,13 @@
114112
* </ul>
115113
*/
116114
public class EsqlNodeSubclassTests<T extends B, B extends Node<B>> extends NodeSubclassTests {
115+
private static final String ESQL_CORE_CLASS_PREFIX = "org.elasticsearch.xpack.esql.core";
116+
private static final String ESQL_CORE_JAR_LOCATION_SUBSTRING = "x-pack-esql-core";
117+
private static final String ESQL_CLASS_PREFIX = "org.elasticsearch.xpack.esql";
118+
117119
private static final Predicate<String> CLASSNAME_FILTER = className -> {
118-
boolean esqlCore = className.startsWith("org.elasticsearch.xpack.esql.core") != false;
119-
boolean esqlProper = className.startsWith("org.elasticsearch.xpack.esql") != false;
120+
boolean esqlCore = className.startsWith(ESQL_CORE_CLASS_PREFIX) != false;
121+
boolean esqlProper = className.startsWith(ESQL_CLASS_PREFIX) != false;
120122
return (esqlCore || esqlProper);
121123
};
122124

@@ -164,15 +166,6 @@ public void testInfoParameters() throws Exception {
164166
*/
165167
expectedCount -= 1;
166168

167-
// special exceptions with private constructors
168-
if (MetadataAttribute.class.equals(subclass) || ReferenceAttribute.class.equals(subclass)) {
169-
expectedCount++;
170-
}
171-
172-
if (FieldAttribute.class.equals(subclass)) {
173-
expectedCount += 2;
174-
}
175-
176169
assertEquals(expectedCount, info(node).properties().size());
177170
}
178171

@@ -736,7 +729,7 @@ public static <T> Set<Class<? extends T>> subclassesOf(Class<T> clazz, Predicate
736729
// NIO FileSystem API is not used since it trips the SecurityManager
737730
// https://bugs.openjdk.java.net/browse/JDK-8160798
738731
// so iterate the jar "by hand"
739-
if (path.endsWith(".jar") && path.contains("x-pack-ql")) {
732+
if (path.endsWith(".jar") && path.contains(ESQL_CORE_JAR_LOCATION_SUBSTRING)) {
740733
try (JarInputStream jar = jarStream(root)) {
741734
JarEntry je = null;
742735
while ((je = jar.getNextJarEntry()) != null) {

0 commit comments

Comments
 (0)