Skip to content

Commit 33ad22e

Browse files
Drop always-id match_field from ListPathSegment runtime metadata (#1241)
## What Removes the `match_field` attribute from `ListPathSegment` in the runtime metadata, and switches the list-vs-object segment discriminator in `SourcedFromNestedPathSegment.from_hash` from `match_field` to `source_field`. ## Why `match_field` was always `"id"` — ElasticGraph relationships join on `id` via foreign keys, so the value carried no information. Serializing a constant into runtime metadata adds noise without value, and keeping it would have meant emitting `match_field: "id"` into `runtime_metadata.yaml` once nested sourced paths are actually populated. This mirrors the equivalent cleanup already applied to the schema-definition `PathSegment` in #1238. The match is now implicit: list elements are matched on `id` against the value at `source_field`. If non-`id` primary keys are supported in the future, the field can be reintroduced then. ## Scope / risk Low. `ListPathSegment` is not yet constructed by any production code — only by the round-trip serialization unit test — so there is no schema-artifact churn and nothing downstream consumes the removed field. Specs and type checks pass.
1 parent 6814370 commit 33ad22e

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/sourced_from_nested_path_segment.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module RuntimeMetadata
1212
# @private
1313
module SourcedFromNestedPathSegment
1414
def self.from_hash(hash)
15-
if hash.key?(ListPathSegment::MATCH_FIELD)
15+
if hash.key?(ListPathSegment::SOURCE_FIELD)
1616
ListPathSegment.from_hash(hash)
1717
else
1818
ObjectPathSegment.from_hash(hash)
@@ -21,24 +21,25 @@ def self.from_hash(hash)
2121
end
2222

2323
# Represents a segment in a nested sourced path that navigates into a list field,
24-
# matching an element by a key field.
24+
# matching an element by its `id` against the value at `source_field`. The match is
25+
# always on `id` (relationships join on `id` via foreign keys), so it's implicit rather
26+
# than stored here.
2527
#
2628
# A future PR will add `to_painless_param` to convert these segments into the
2729
# camelCase hash format expected by the painless script (with a "type" discriminator).
2830
#
2931
# @private
30-
class ListPathSegment < ::Data.define(:field, :match_field, :source_field)
32+
class ListPathSegment < ::Data.define(:field, :source_field)
3133
FIELD = "field"
32-
MATCH_FIELD = "match_field"
3334
SOURCE_FIELD = "source_field"
3435

3536
def to_dumpable_hash
3637
# Keys here are ordered alphabetically; please keep them that way
37-
{FIELD => field, MATCH_FIELD => match_field, SOURCE_FIELD => source_field}
38+
{FIELD => field, SOURCE_FIELD => source_field}
3839
end
3940

4041
def self.from_hash(hash)
41-
new(field: hash[FIELD], match_field: hash[MATCH_FIELD], source_field: hash[SOURCE_FIELD])
42+
new(field: hash[FIELD], source_field: hash[SOURCE_FIELD])
4243
end
4344
end
4445

elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/sourced_from_nested_path_segment.rbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ module ElasticGraph
33
module RuntimeMetadata
44
class ListPathSegmentSuperType
55
attr_reader field: ::String
6-
attr_reader match_field: ::String
76
attr_reader source_field: ::String
87

9-
def initialize: (field: ::String, match_field: ::String, source_field: ::String) -> void
8+
def initialize: (field: ::String, source_field: ::String) -> void
109
end
1110

1211
class ListPathSegment < ListPathSegmentSuperType
1312
FIELD: "field"
14-
MATCH_FIELD: "match_field"
1513
SOURCE_FIELD: "source_field"
1614

1715
def self.from_hash: (::Hash[::String, untyped]) -> ListPathSegment

elasticgraph-schema_artifacts/spec/unit/elastic_graph/schema_artifacts/runtime_metadata/schema_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module RuntimeMetadata
130130
has_had_multiple_sources: false,
131131
sourced_from_nested_paths_by_relationship: {
132132
"currency" => [
133-
ListPathSegment.new(field: "costs", match_field: "id", source_field: "cost_id"),
133+
ListPathSegment.new(field: "costs", source_field: "cost_id"),
134134
ObjectPathSegment.new(field: "details")
135135
]
136136
}
@@ -281,7 +281,7 @@ module RuntimeMetadata
281281
},
282282
"sourced_from_nested_paths_by_relationship" => {
283283
"currency" => [
284-
{"field" => "costs", "match_field" => "id", "source_field" => "cost_id"},
284+
{"field" => "costs", "source_field" => "cost_id"},
285285
{"field" => "details"}
286286
]
287287
}

0 commit comments

Comments
 (0)