Skip to content

Commit 6609e73

Browse files
authored
ESQL: Refactor named writeable entries for expressions and plans (elastic#117029) (elastic#117101)
Move writable declarations outside the core classes to avoid errors (such as subClass.getNamedWritable()) and centralize them in a top package class for better management. Make all touched serialization code the same as in the initial PR, except for the fact that LookupJoin/LookupJoinExec are missing. (cherry picked from commit 0b74492)
1 parent c029282 commit 6609e73

File tree

41 files changed

+674
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+674
-493
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.esql.core.expression;
88

9-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
109
import org.elasticsearch.core.Nullable;
1110
import org.elasticsearch.xpack.esql.core.tree.Source;
1211
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -34,11 +33,6 @@ public abstract class Attribute extends NamedExpression {
3433
*/
3534
protected static final String SYNTHETIC_ATTRIBUTE_NAME_PREFIX = "$$";
3635

37-
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
38-
// TODO add UnsupportedAttribute when these are moved to the same project
39-
return List.of(FieldAttribute.ENTRY, MetadataAttribute.ENTRY, ReferenceAttribute.ENTRY);
40-
}
41-
4236
// can the attr be null - typically used in JOINs
4337
private final Nullability nullability;
4438

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.esql.core.expression;
88

9-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
109
import org.elasticsearch.xpack.esql.core.QlIllegalArgumentException;
1110
import org.elasticsearch.xpack.esql.core.capabilities.Resolvable;
1211
import org.elasticsearch.xpack.esql.core.capabilities.Resolvables;
@@ -15,7 +14,6 @@
1514
import org.elasticsearch.xpack.esql.core.type.DataType;
1615
import org.elasticsearch.xpack.esql.core.util.StringUtils;
1716

18-
import java.util.ArrayList;
1917
import java.util.List;
2018
import java.util.function.Supplier;
2119

@@ -29,14 +27,6 @@
2927
* (which is a type of expression) with a single child, c.
3028
*/
3129
public abstract class Expression extends Node<Expression> implements Resolvable {
32-
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
33-
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
34-
for (NamedWriteableRegistry.Entry e : NamedExpression.getNamedWriteables()) {
35-
entries.add(new NamedWriteableRegistry.Entry(Expression.class, e.name, in -> (NamedExpression) e.reader.read(in)));
36-
}
37-
entries.add(Literal.ENTRY);
38-
return entries;
39-
}
4030

4131
public static class TypeResolution {
4232
private final boolean failed;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.core.expression;
9+
10+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
public class ExpressionCoreWritables {
16+
17+
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
18+
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
19+
entries.addAll(expressions());
20+
entries.addAll(namedExpressions());
21+
entries.addAll(attributes());
22+
return entries;
23+
}
24+
25+
public static List<NamedWriteableRegistry.Entry> expressions() {
26+
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
27+
// add entries as expressions
28+
for (NamedWriteableRegistry.Entry e : namedExpressions()) {
29+
entries.add(new NamedWriteableRegistry.Entry(Expression.class, e.name, in -> (Expression) e.reader.read(in)));
30+
}
31+
entries.add(Literal.ENTRY);
32+
return entries;
33+
}
34+
35+
public static List<NamedWriteableRegistry.Entry> namedExpressions() {
36+
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
37+
// add entries as named writeables
38+
for (NamedWriteableRegistry.Entry e : attributes()) {
39+
entries.add(new NamedWriteableRegistry.Entry(NamedExpression.class, e.name, in -> (NamedExpression) e.reader.read(in)));
40+
}
41+
entries.add(Alias.ENTRY);
42+
return entries;
43+
}
44+
45+
public static List<NamedWriteableRegistry.Entry> attributes() {
46+
return List.of(FieldAttribute.ENTRY, MetadataAttribute.ENTRY, ReferenceAttribute.ENTRY);
47+
}
48+
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
package org.elasticsearch.xpack.esql.core.expression;
88

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

14-
import java.util.ArrayList;
1513
import java.util.List;
1614
import java.util.Objects;
1715

@@ -20,14 +18,6 @@
2018
* (by converting to an attribute).
2119
*/
2220
public abstract class NamedExpression extends Expression implements NamedWriteable {
23-
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
24-
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
25-
for (NamedWriteableRegistry.Entry e : Attribute.getNamedWriteables()) {
26-
entries.add(new NamedWriteableRegistry.Entry(NamedExpression.class, e.name, in -> (NamedExpression) e.reader.read(in)));
27-
}
28-
entries.add(Alias.ENTRY);
29-
return entries;
30-
}
3121

3222
private final String name;
3323
private final NameId id;

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/predicate/fulltext/FullTextPredicate.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.esql.core.expression.predicate.fulltext;
88

9-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
109
import org.elasticsearch.common.io.stream.StreamInput;
1110
import org.elasticsearch.common.io.stream.StreamOutput;
1211
import org.elasticsearch.core.Nullable;
@@ -23,10 +22,6 @@
2322

2423
public abstract class FullTextPredicate extends Expression {
2524

26-
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
27-
return List.of(MatchQueryPredicate.ENTRY, MultiMatchQueryPredicate.ENTRY, StringQueryPredicate.ENTRY);
28-
}
29-
3025
public enum Operator {
3126
AND,
3227
OR;

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/Block.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
import org.apache.lucene.util.Accountable;
1111
import org.apache.lucene.util.RamUsageEstimator;
1212
import org.elasticsearch.common.io.stream.NamedWriteable;
13-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1413
import org.elasticsearch.common.unit.ByteSizeValue;
1514
import org.elasticsearch.core.RefCounted;
1615
import org.elasticsearch.core.Releasable;
1716
import org.elasticsearch.core.ReleasableIterator;
1817
import org.elasticsearch.core.Releasables;
1918
import org.elasticsearch.index.mapper.BlockLoader;
2019

21-
import java.util.List;
22-
2320
/**
2421
* A Block is a columnar representation of homogenous data. It has a position (row) count, and
2522
* various data retrieval methods for accessing the underlying data that is stored at a given
@@ -291,19 +288,6 @@ static Block[] buildAll(Block.Builder... builders) {
291288
}
292289
}
293290

294-
static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
295-
return List.of(
296-
IntBlock.ENTRY,
297-
LongBlock.ENTRY,
298-
FloatBlock.ENTRY,
299-
DoubleBlock.ENTRY,
300-
BytesRefBlock.ENTRY,
301-
BooleanBlock.ENTRY,
302-
ConstantNullBlock.ENTRY,
303-
CompositeBlock.ENTRY
304-
);
305-
}
306-
307291
/**
308292
* Serialization type for blocks: 0 and 1 replace false/true used in pre-8.14
309293
*/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.compute.data;
9+
10+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
11+
12+
import java.util.List;
13+
14+
public class BlockWritables {
15+
16+
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
17+
return List.of(
18+
IntBlock.ENTRY,
19+
LongBlock.ENTRY,
20+
FloatBlock.ENTRY,
21+
DoubleBlock.ENTRY,
22+
BytesRefBlock.ENTRY,
23+
BooleanBlock.ENTRY,
24+
ConstantNullBlock.ENTRY,
25+
CompositeBlock.ENTRY
26+
);
27+
}
28+
}

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/SerializationTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public abstract class SerializationTestCase extends ESTestCase {
3030
BigArrays bigArrays;
3131
protected BlockFactory blockFactory;
32-
NamedWriteableRegistry registry = new NamedWriteableRegistry(Block.getNamedWriteables());
32+
NamedWriteableRegistry registry = new NamedWriteableRegistry(BlockWritables.getNamedWriteables());
3333

3434
@Before
3535
public final void newBlockFactory() {

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/exchange/ExchangeServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.elasticsearch.common.util.PageCacheRecycler;
2323
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
2424
import org.elasticsearch.common.util.concurrent.EsExecutors;
25-
import org.elasticsearch.compute.data.Block;
2625
import org.elasticsearch.compute.data.BlockFactory;
26+
import org.elasticsearch.compute.data.BlockWritables;
2727
import org.elasticsearch.compute.data.IntBlock;
2828
import org.elasticsearch.compute.data.MockBlockFactory;
2929
import org.elasticsearch.compute.data.Page;
@@ -457,7 +457,7 @@ public void sendResponse(TransportResponse transportResponse) {
457457

458458
private MockTransportService newTransportService() {
459459
List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>(ClusterModule.getNamedWriteables());
460-
namedWriteables.addAll(Block.getNamedWriteables());
460+
namedWriteables.addAll(BlockWritables.getNamedWriteables());
461461
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
462462
MockTransportService service = MockTransportService.createNewService(
463463
Settings.EMPTY,

0 commit comments

Comments
 (0)