Skip to content

Commit 53bcc3e

Browse files
authored
Replace tuple with record (#128976)
1 parent 30e620b commit 53bcc3e

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
1313
import org.elasticsearch.core.Nullable;
14-
import org.elasticsearch.core.Tuple;
1514
import org.elasticsearch.index.mapper.IdFieldMapper;
1615
import org.elasticsearch.index.mapper.IgnoredFieldMapper;
1716
import org.elasticsearch.index.mapper.IndexModeFieldMapper;
@@ -26,8 +25,6 @@
2625
import java.util.Map;
2726
import java.util.Objects;
2827

29-
import static org.elasticsearch.core.Tuple.tuple;
30-
3128
public class MetadataAttribute extends TypedAttribute {
3229
public static final String TIMESTAMP_FIELD = "@timestamp"; // this is not a true metadata attribute
3330
public static final String TSID_FIELD = "_tsid";
@@ -40,23 +37,19 @@ public class MetadataAttribute extends TypedAttribute {
4037
MetadataAttribute::readFrom
4138
);
4239

43-
private static final Map<String, Tuple<DataType, Boolean>> ATTRIBUTES_MAP = Map.of(
44-
"_version",
45-
tuple(DataType.LONG, false), // _version field is not searchable
46-
INDEX,
47-
tuple(DataType.KEYWORD, true),
48-
IdFieldMapper.NAME,
49-
tuple(DataType.KEYWORD, false), // actually searchable, but fielddata access on the _id field is disallowed by default
50-
IgnoredFieldMapper.NAME,
51-
tuple(DataType.KEYWORD, true),
52-
SourceFieldMapper.NAME,
53-
tuple(DataType.SOURCE, false),
54-
IndexModeFieldMapper.NAME,
55-
tuple(DataType.KEYWORD, true),
56-
SCORE,
57-
tuple(DataType.DOUBLE, false)
40+
private static final Map<String, MetadataAttributeConfiguration> ATTRIBUTES_MAP = Map.ofEntries(
41+
Map.entry("_version", new MetadataAttributeConfiguration(DataType.LONG, false)),
42+
Map.entry(INDEX, new MetadataAttributeConfiguration(DataType.KEYWORD, true)),
43+
// actually _id is searchable, but fielddata access on it is disallowed by default
44+
Map.entry(IdFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.KEYWORD, false)),
45+
Map.entry(IgnoredFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.KEYWORD, true)),
46+
Map.entry(SourceFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.SOURCE, false)),
47+
Map.entry(IndexModeFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.KEYWORD, true)),
48+
Map.entry(SCORE, new MetadataAttributeConfiguration(DataType.DOUBLE, false))
5849
);
5950

51+
private record MetadataAttributeConfiguration(DataType dataType, boolean searchable) {}
52+
6053
private final boolean searchable;
6154

6255
public MetadataAttribute(
@@ -160,12 +153,12 @@ public boolean searchable() {
160153

161154
public static MetadataAttribute create(Source source, String name) {
162155
var t = ATTRIBUTES_MAP.get(name);
163-
return t != null ? new MetadataAttribute(source, name, t.v1(), t.v2()) : null;
156+
return t != null ? new MetadataAttribute(source, name, t.dataType(), t.searchable()) : null;
164157
}
165158

166159
public static DataType dataType(String name) {
167160
var t = ATTRIBUTES_MAP.get(name);
168-
return t != null ? t.v1() : null;
161+
return t != null ? t.dataType() : null;
169162
}
170163

171164
public static boolean isSupported(String name) {

0 commit comments

Comments
 (0)