Class: ElasticGraph::SchemaDefinition::SchemaElements::SubAggregationPath
- Inherits:
-
Data
- Object
- Data
- ElasticGraph::SchemaDefinition::SchemaElements::SubAggregationPath
- Defined in:
- lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb
Overview
Abstraction responsible for identifying paths to sub-aggregations, and, on that basis, determining what the type names should be.
Instance Attribute Summary collapse
-
#field_path ⇒ Object
readonly
Returns the value of attribute field_path.
-
#parent_doc_types ⇒ Object
readonly
Returns the value of attribute parent_doc_types.
Class Method Summary collapse
-
.paths_for(type, schema_def_state:) ⇒ Object
Determines the set of sub aggregation paths for the given type.
Instance Method Summary collapse
Instance Attribute Details
#field_path ⇒ Object (readonly)
Returns the value of attribute field_path
16 17 18 |
# File 'lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb', line 16 def field_path @field_path end |
#parent_doc_types ⇒ Object (readonly)
Returns the value of attribute parent_doc_types
16 17 18 |
# File 'lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb', line 16 def parent_doc_types @parent_doc_types end |
Class Method Details
.paths_for(type, schema_def_state:) ⇒ Object
Determines the set of sub aggregation paths for the given type.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb', line 30 def self.paths_for(type, schema_def_state:) root_paths = type.indexed? ? [SubAggregationPath.new([type.name], [])] : [] # : ::Array[SubAggregationPath] non_relation_field_refs = schema_def_state .user_defined_field_references_by_type_name.fetch(type.name) { [] } # Relationship fields are the only case where types can reference each other in circular fashion. # If we don't reject that case here, we can get stuck in infinite recursion. .reject(&:relationship) root_paths + non_relation_field_refs.flat_map do |field_ref| # Here we call `schema_def_state.sub_aggregation_paths_for` rather than directly # recursing to give schema_def_state a chance to cache the results. parent_paths = schema_def_state.sub_aggregation_paths_for(field_ref.parent_type) if field_ref.nested? parent_paths.map { |path| path.plus_parent(field_ref.type_for_derived_types.fully_unwrapped.name) } else parent_paths.map { |path| path.plus_field(field_ref) } end end end |
Instance Method Details
#field_path_string ⇒ Object
60 61 62 |
# File 'lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb', line 60 def field_path_string field_path.map(&:name).join(".") end |
#plus_field(field) ⇒ Object
56 57 58 |
# File 'lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb', line 56 def plus_field(field) with(field_path: field_path + [field]) end |
#plus_parent(parent) ⇒ Object
52 53 54 |
# File 'lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb', line 52 def plus_parent(parent) with(parent_doc_types: parent_doc_types + [parent], field_path: []) end |