Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module RuntimeMetadata
# @private
module SourcedFromNestedPathSegment
def self.from_hash(hash)
if hash.key?(ListPathSegment::MATCH_FIELD)
if hash.key?(ListPathSegment::SOURCE_FIELD)
ListPathSegment.from_hash(hash)
else
ObjectPathSegment.from_hash(hash)
Expand All @@ -21,24 +21,25 @@ def self.from_hash(hash)
end

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

def to_dumpable_hash
# Keys here are ordered alphabetically; please keep them that way
{FIELD => field, MATCH_FIELD => match_field, SOURCE_FIELD => source_field}
{FIELD => field, SOURCE_FIELD => source_field}
end

def self.from_hash(hash)
new(field: hash[FIELD], match_field: hash[MATCH_FIELD], source_field: hash[SOURCE_FIELD])
new(field: hash[FIELD], source_field: hash[SOURCE_FIELD])
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ module ElasticGraph
module RuntimeMetadata
class ListPathSegmentSuperType
attr_reader field: ::String
attr_reader match_field: ::String
attr_reader source_field: ::String

def initialize: (field: ::String, match_field: ::String, source_field: ::String) -> void
def initialize: (field: ::String, source_field: ::String) -> void
end

class ListPathSegment < ListPathSegmentSuperType
FIELD: "field"
MATCH_FIELD: "match_field"
SOURCE_FIELD: "source_field"

def self.from_hash: (::Hash[::String, untyped]) -> ListPathSegment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ module RuntimeMetadata
has_had_multiple_sources: false,
sourced_from_nested_paths_by_relationship: {
"currency" => [
ListPathSegment.new(field: "costs", match_field: "id", source_field: "cost_id"),
ListPathSegment.new(field: "costs", source_field: "cost_id"),
ObjectPathSegment.new(field: "details")
]
}
Expand Down Expand Up @@ -281,7 +281,7 @@ module RuntimeMetadata
},
"sourced_from_nested_paths_by_relationship" => {
"currency" => [
{"field" => "costs", "match_field" => "id", "source_field" => "cost_id"},
{"field" => "costs", "source_field" => "cost_id"},
{"field" => "details"}
]
}
Expand Down