From 713d132126e46d8f100fbd0ed87ca48266c64b44 Mon Sep 17 00:00:00 2001 From: myronmarston-toast Date: Tue, 10 Nov 2026 17:26:05 -0800 Subject: [PATCH] test: assert which sub-aggregation groupings use `missing` aggregations A grouping without a missing value placeholder needs a separate `missing` aggregation at every sub-aggregation level, so the number of aggregations grows exponentially. These assertions record which groupings do that today, so changes to placeholder handling show up in the specs. - Add `missing_aggregation_field_paths_from_queries`, which reads the recorded msearch requests, and `expect_last_query_to_use_missing_aggregations_on`, which asserts on the last search. - Add an `after` hook that fails any datastore test whose searches use `missing` aggregations, unless the test has the `:expect_missing_aggregations` tag. - Assert on it in the sub-aggregation acceptance specs (term, date histogram, `as_day_of_week`, `as_time_of_day` and geo tile groupings), in the `DatastoreQuery` sub-aggregation integration spec, and in the Apollo entity ref sub-aggregation spec. On `main`, `Boolean`, entity ref, date histogram, script term and geo tile groupings use `missing` aggregations. - Add a `SeasonResult` enum field to `TeamSeason` so the specs cover grouping on an enum in a sub-aggregation. Generated with Claude Code --- config/proto_field_numbers.yaml | 9 +- config/schema/artifacts/data_warehouse.yaml | 8 +- config/schema/artifacts/datastore_config.yaml | 10 + config/schema/artifacts/json_schemas.yaml | 11 ++ .../artifacts/json_schemas_by_version/v1.yaml | 14 ++ config/schema/artifacts/runtime_metadata.yaml | 26 +++ config/schema/artifacts/schema.graphql | 176 ++++++++++++++++++ config/schema/artifacts/schema.proto | 11 ++ .../artifacts_with_apollo/data_warehouse.yaml | 8 +- .../datastore_config.yaml | 10 + .../artifacts_with_apollo/json_schemas.yaml | 11 ++ .../json_schemas_by_version/v1.yaml | 14 ++ .../runtime_metadata.yaml | 26 +++ .../artifacts_with_apollo/schema.graphql | 176 ++++++++++++++++++ .../schema/artifacts_with_apollo/schema.proto | 11 ++ config/schema/teams.rb | 5 + .../apollo_entity_ref_resolver_spec.rb | 3 +- .../spec/acceptance/hidden_types_spec.rb | 1 + .../spec/acceptance/sub_aggregations_spec.rb | 44 ++++- .../datastore_query/sub_aggregations_spec.rb | 24 ++- .../spec/acceptance/list_fields_spec.rb | 1 + .../spec_support/factories/teams.rb | 1 + .../spec_support/uses_datastore.rb | 31 +++ 23 files changed, 608 insertions(+), 23 deletions(-) diff --git a/config/proto_field_numbers.yaml b/config/proto_field_numbers.yaml index 88a3f6ad0..a5ed5ad8a 100644 --- a/config/proto_field_numbers.yaml +++ b/config/proto_field_numbers.yaml @@ -284,7 +284,8 @@ messages: players_nested: 8 players_object: 9 stadium_location: 10 - next_number: 11 + result: 11 + next_number: 12 Widget: fields: id: 1 @@ -355,6 +356,12 @@ enums: ALLOY: 1 CARBON_FIBER: 2 next_number: 3 + SeasonResult: + values: + WON_CHAMPIONSHIP: 1 + MADE_PLAYOFFS: 2 + MISSED_PLAYOFFS: 3 + next_number: 4 Size: values: SMALL: 1 diff --git a/config/schema/artifacts/data_warehouse.yaml b/config/schema/artifacts/data_warehouse.yaml index e3d97eb4c..5ae3527c6 100644 --- a/config/schema/artifacts/data_warehouse.yaml +++ b/config/schema/artifacts/data_warehouse.yaml @@ -106,10 +106,10 @@ tables: forbes_valuation_moneys_object ARRAY>, current_players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, current_players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, - seasons_nested ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, - seasons_object ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, - the_nested_fields STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, - nested_fields2 STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, + seasons_nested ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, + seasons_object ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, + the_nested_fields STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, + nested_fields2 STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, staff STRUCT>, general_manager STRUCT> ) widget_currencies: diff --git a/config/schema/artifacts/datastore_config.yaml b/config/schema/artifacts/datastore_config.yaml index f3e33b8b2..3587b0e30 100644 --- a/config/schema/artifacts/datastore_config.yaml +++ b/config/schema/artifacts/datastore_config.yaml @@ -201,6 +201,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -402,6 +404,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -653,6 +657,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -942,6 +948,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -1212,6 +1220,8 @@ index_templates: type: integer seasons_object|the_record|first_win_on: type: integer + seasons_object|result: + type: integer seasons_object|year: type: integer seasons_object|notes: diff --git a/config/schema/artifacts/json_schemas.yaml b/config/schema/artifacts/json_schemas.yaml index 4195237ff..035e0d191 100644 --- a/config/schema/artifacts/json_schemas.yaml +++ b/config/schema/artifacts/json_schemas.yaml @@ -794,6 +794,12 @@ json_schema_version: 1 required: - x - "y" + SeasonResult: + type: string + enum: + - WON_CHAMPIONSHIP + - MADE_PLAYOFFS + - MISSED_PLAYOFFS Size: type: string enum: @@ -1044,6 +1050,10 @@ json_schema_version: 1 anyOf: - "$ref": "#/$defs/TeamRecord" - type: 'null' + result: + anyOf: + - "$ref": "#/$defs/SeasonResult" + - type: 'null' year: anyOf: - "$ref": "#/$defs/Int" @@ -1088,6 +1098,7 @@ json_schema_version: 1 default: TeamSeason required: - record + - result - year - notes - count diff --git a/config/schema/artifacts/json_schemas_by_version/v1.yaml b/config/schema/artifacts/json_schemas_by_version/v1.yaml index 5b814f6ba..1f8944dbe 100644 --- a/config/schema/artifacts/json_schemas_by_version/v1.yaml +++ b/config/schema/artifacts/json_schemas_by_version/v1.yaml @@ -1040,6 +1040,12 @@ json_schema_version: 1 required: - x - "y" + SeasonResult: + type: string + enum: + - WON_CHAMPIONSHIP + - MADE_PLAYOFFS + - MISSED_PLAYOFFS Size: type: string enum: @@ -1395,6 +1401,13 @@ json_schema_version: 1 ElasticGraph: type: TeamRecord nameInIndex: the_record + result: + anyOf: + - "$ref": "#/$defs/SeasonResult" + - type: 'null' + ElasticGraph: + type: SeasonResult + nameInIndex: result year: anyOf: - "$ref": "#/$defs/Int" @@ -1466,6 +1479,7 @@ json_schema_version: 1 default: TeamSeason required: - record + - result - year - notes - count diff --git a/config/schema/artifacts/runtime_metadata.yaml b/config/schema/artifacts/runtime_metadata.yaml index 1b0a289e0..0a264c634 100644 --- a/config/schema/artifacts/runtime_metadata.yaml +++ b/config/schema/artifacts/runtime_metadata.yaml @@ -2128,6 +2128,8 @@ index_definitions_by_name: source: __self __counts.seasons_object|players_object|seasons_object|year: source: __self + __counts.seasons_object|result: + source: __self __counts.seasons_object|stadium_location: source: __self __counts.seasons_object|stadium_location|lat: @@ -2452,6 +2454,8 @@ index_definitions_by_name: source: __self nested_fields2.the_seasons.players_object.seasons_object.year: source: __self + nested_fields2.the_seasons.result: + source: __self nested_fields2.the_seasons.stadium_location.lat: source: __self nested_fields2.the_seasons.stadium_location.lon: @@ -2598,6 +2602,8 @@ index_definitions_by_name: source: __self seasons_nested.players_object.seasons_object.year: source: __self + seasons_nested.result: + source: __self seasons_nested.stadium_location.lat: source: __self seasons_nested.stadium_location.lon: @@ -2706,6 +2712,8 @@ index_definitions_by_name: source: __self seasons_object.players_object.seasons_object.year: source: __self + seasons_object.result: + source: __self seasons_object.stadium_location.lat: source: __self seasons_object.stadium_location.lon: @@ -2924,6 +2932,8 @@ index_definitions_by_name: source: __self the_nested_fields.the_seasons.players_object.seasons_object.year: source: __self + the_nested_fields.the_seasons.result: + source: __self the_nested_fields.the_seasons.stadium_location.lat: source: __self the_nested_fields.the_seasons.stadium_location.lon: @@ -6800,6 +6810,10 @@ object_types_by_name: resolver: name: object_without_lookahead graphql_only_return_type: true + SeasonResultListFilterInput: + graphql_fields_by_name: + count: + name_in_index: __counts SizeListFilterInput: graphql_fields_by_name: count: @@ -7839,6 +7853,9 @@ object_types_by_name: name_in_index: the_record resolver: name: get_record_field_value + result: + resolver: + name: get_record_field_value stadium_location: resolver: name: get_record_field_value @@ -7869,6 +7886,9 @@ object_types_by_name: name_in_index: the_record resolver: name: object_with_lookahead + result: + resolver: + name: object_with_lookahead stadium_location: resolver: name: object_with_lookahead @@ -7908,6 +7928,9 @@ object_types_by_name: name_in_index: the_record resolver: name: object_with_lookahead + result: + resolver: + name: object_with_lookahead stadium_location: resolver: name: object_with_lookahead @@ -7935,6 +7958,9 @@ object_types_by_name: players_object: resolver: name: get_record_field_value + result: + resolver: + name: get_record_field_value TeamSeasonListFilterInput: graphql_fields_by_name: count: diff --git a/config/schema/artifacts/schema.graphql b/config/schema/artifacts/schema.graphql index 87d398670..135dead7a 100644 --- a/config/schema/artifacts/schema.graphql +++ b/config/schema/artifacts/schema.graphql @@ -12252,6 +12252,152 @@ type SearchHighlight { snippets: [String!]! } +enum SeasonResult { + MADE_PLAYOFFS + MISSED_PLAYOFFS + WON_CHAMPIONSHIP +} + +""" +Input type used to specify filters on `SeasonResult` fields. + +Will match all documents if passed as an empty object (or as `null`). +""" +input SeasonResultFilterInput { + """ + Matches records where all of the provided sub-filters evaluate to true. This works just like an AND operator in SQL. + + Note: multiple filters are automatically ANDed together. This is only needed when you have multiple filters that can't + be provided on a single `SeasonResultFilterInput` input because of collisions + between key names. For example, if you want to AND multiple + OR'd sub-filters (the equivalent of (A OR B) AND (C OR D)), you could do all_of: [{any_of: [...]}, {any_of: [...]}]. + + When `null` or an empty list is passed, matches all documents. + """ + all_of: [SeasonResultFilterInput!] + + """ + Matches records where any of the provided sub-filters evaluate to true. + This works just like an OR operator in SQL. + + When `null` is passed, matches all documents. + When an empty list is passed, this part of the filter matches no documents. + """ + any_of: [SeasonResultFilterInput!] + + """ + Matches records where the field value is equal to any of the provided values. + This works just like an IN operator in SQL. + + When `null` is passed, matches all documents. When an empty list is passed, + this part of the filter matches no documents. When `null` is passed in the + list, this part of the filter matches records where the field value is `null`. + """ + equal_to_any_of: [SeasonResultInput] + + """ + Matches records where the provided sub-filter evaluates to false. + This works just like a NOT operator in SQL. + + When `null` or an empty object is passed, matches no documents. + """ + not: SeasonResultFilterInput +} + +enum SeasonResultInput { + MADE_PLAYOFFS + MISSED_PLAYOFFS + WON_CHAMPIONSHIP +} + +""" +Input type used to specify filters on elements of a `[SeasonResult]` field. + +Will match all documents if passed as an empty object (or as `null`). +""" +input SeasonResultListElementFilterInput { + """ + Matches records where all of the provided sub-filters evaluate to true. This works just like an AND operator in SQL. + + Note: multiple filters are automatically ANDed together. This is only needed when you have multiple filters that can't + be provided on a single `SeasonResultListElementFilterInput` input because of + collisions between key names. For example, if you want to AND multiple + OR'd sub-filters (the equivalent of (A OR B) AND (C OR D)), you could do all_of: [{any_of: [...]}, {any_of: [...]}]. + + When `null` or an empty list is passed, matches all documents. + """ + all_of: [SeasonResultListElementFilterInput!] + + """ + Matches records where any of the provided sub-filters evaluate to true. + This works just like an OR operator in SQL. + + When `null` is passed, matches all documents. + When an empty list is passed, this part of the filter matches no documents. + """ + any_of: [SeasonResultListElementFilterInput!] + + """ + Matches records where the field value is equal to any of the provided values. + This works just like an IN operator in SQL. + + When `null` is passed, matches all documents. When an empty list is passed, + this part of the filter matches no documents. When `null` is passed in the + list, this part of the filter matches records where the field value is `null`. + """ + equal_to_any_of: [SeasonResultInput!] +} + +""" +Input type used to specify filters on `[SeasonResult]` fields. + +Will match all documents if passed as an empty object (or as `null`). +""" +input SeasonResultListFilterInput { + """ + Matches records where all of the provided sub-filters evaluate to true. This works just like an AND operator in SQL. + + Note: multiple filters are automatically ANDed together. This is only needed when you have multiple filters that can't + be provided on a single `SeasonResultListFilterInput` input because of + collisions between key names. For example, if you want to AND multiple + OR'd sub-filters (the equivalent of (A OR B) AND (C OR D)), you could do all_of: [{any_of: [...]}, {any_of: [...]}]. + + When `null` or an empty list is passed, matches all documents. + """ + all_of: [SeasonResultListFilterInput!] + + """ + Matches records where any of the provided sub-filters evaluate to true. + This works just like an OR operator in SQL. + + When `null` is passed, matches all documents. + When an empty list is passed, this part of the filter matches no documents. + """ + any_of: [SeasonResultListFilterInput!] + + """ + Matches records where any of the list elements match the provided sub-filter. + + When `null` or an empty object is passed, matches all documents. + """ + any_satisfy: SeasonResultListElementFilterInput + + """ + Used to filter on the number of non-null elements in this list field. + + When `null` or an empty object is passed, matches all documents. + """ + count: IntFilterInput + + """ + Matches records where the provided sub-filter evaluates to false. + This works just like a NOT operator in SQL. + + When `null` or an empty object is passed, matches no documents. + """ + not: SeasonResultListFilterInput +} + enum Size { LARGE MEDIUM @@ -15186,6 +15332,7 @@ type TeamSeason { players_nested: [Player!]! players_object: [Player!]! record: TeamRecord + result: SeasonResult stadium_location: GeoLocation started_at: DateTime was_shortened: Boolean @@ -15217,6 +15364,11 @@ type TeamSeasonAggregatedValues { """ record: TeamRecordAggregatedValues + """ + Computed aggregate values for the `result` field. + """ + result: NonNumericAggregatedValues + """ Computed aggregate values for the `stadium_location` field. """ @@ -15315,6 +15467,13 @@ input TeamSeasonFieldsListFilterInput { """ record: TeamRecordFieldsListFilterInput + """ + Used to filter on the `result` field. + + When `null` or an empty object is passed, matches all documents. + """ + result: SeasonResultListFilterInput + """ Used to filter on the `stadium_location` field. @@ -15421,6 +15580,13 @@ input TeamSeasonFilterInput { """ record: TeamRecordFilterInput + """ + Used to filter on the `result` field. + + When `null` or an empty object is passed, matches all documents. + """ + result: SeasonResultFilterInput + """ Used to filter on the `stadium_location` field. @@ -15494,6 +15660,11 @@ type TeamSeasonGroupedBy { """ record: TeamRecordGroupedBy + """ + The `result` field value for this group. + """ + result: SeasonResult + """ Offers the different grouping options for the `stadium_location` value within this group. """ @@ -15544,6 +15715,11 @@ type TeamSeasonHighlights { Search highlights for the `players_object`, providing snippets of the matching text. """ players_object: PlayerHighlights + + """ + Search highlights for the `result`, providing snippets of the matching text. + """ + result: [String!]! } """ diff --git a/config/schema/artifacts/schema.proto b/config/schema/artifacts/schema.proto index a996522af..bdf310543 100644 --- a/config/schema/artifacts/schema.proto +++ b/config/schema/artifacts/schema.proto @@ -258,6 +258,16 @@ message Position { optional double y = 2; } +enum SeasonResult { + // The default value when no enum value has been explicitly set. Do not use this value. + // See https://protobuf.dev/programming-guides/proto3/#enum-default. + SEASON_RESULT_UNSPECIFIED = 0; + + SEASON_RESULT_WON_CHAMPIONSHIP = 1; + SEASON_RESULT_MADE_PLAYOFFS = 2; + SEASON_RESULT_MISSED_PLAYOFFS = 3; +} + enum Size { // The default value when no enum value has been explicitly set. Do not use this value. // See https://protobuf.dev/programming-guides/proto3/#enum-default. @@ -333,6 +343,7 @@ message TeamRecord { message TeamSeason { optional .elasticgraph.TeamRecord record = 1; + optional .elasticgraph.SeasonResult result = 11; optional int32 year = 2; repeated string notes = 3; optional int32 count = 4; diff --git a/config/schema/artifacts_with_apollo/data_warehouse.yaml b/config/schema/artifacts_with_apollo/data_warehouse.yaml index e3d97eb4c..5ae3527c6 100644 --- a/config/schema/artifacts_with_apollo/data_warehouse.yaml +++ b/config/schema/artifacts_with_apollo/data_warehouse.yaml @@ -106,10 +106,10 @@ tables: forbes_valuation_moneys_object ARRAY>, current_players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, current_players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, - seasons_nested ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, - seasons_object ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, - the_nested_fields STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, - nested_fields2 STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, + seasons_nested ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, + seasons_object ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>, + the_nested_fields STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, + nested_fields2 STRUCT>, current_players ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, the_seasons ARRAY, result STRING, year INT, notes ARRAY, count INT, started_at TIMESTAMP, won_games_at ARRAY, was_shortened BOOLEAN, stadium_location STRUCT, players_nested ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>, players_object ARRAY, affiliations STRUCT>>, sponsorships_object ARRAY>>>, seasons_nested ARRAY>>, seasons_object ARRAY>>>>>>>, staff STRUCT>, general_manager STRUCT> ) widget_currencies: diff --git a/config/schema/artifacts_with_apollo/datastore_config.yaml b/config/schema/artifacts_with_apollo/datastore_config.yaml index f3e33b8b2..3587b0e30 100644 --- a/config/schema/artifacts_with_apollo/datastore_config.yaml +++ b/config/schema/artifacts_with_apollo/datastore_config.yaml @@ -201,6 +201,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -402,6 +404,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -653,6 +657,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -942,6 +948,8 @@ index_templates: first_win_on: type: date format: strict_date + result: + type: keyword year: type: integer notes: @@ -1212,6 +1220,8 @@ index_templates: type: integer seasons_object|the_record|first_win_on: type: integer + seasons_object|result: + type: integer seasons_object|year: type: integer seasons_object|notes: diff --git a/config/schema/artifacts_with_apollo/json_schemas.yaml b/config/schema/artifacts_with_apollo/json_schemas.yaml index 4195237ff..035e0d191 100644 --- a/config/schema/artifacts_with_apollo/json_schemas.yaml +++ b/config/schema/artifacts_with_apollo/json_schemas.yaml @@ -794,6 +794,12 @@ json_schema_version: 1 required: - x - "y" + SeasonResult: + type: string + enum: + - WON_CHAMPIONSHIP + - MADE_PLAYOFFS + - MISSED_PLAYOFFS Size: type: string enum: @@ -1044,6 +1050,10 @@ json_schema_version: 1 anyOf: - "$ref": "#/$defs/TeamRecord" - type: 'null' + result: + anyOf: + - "$ref": "#/$defs/SeasonResult" + - type: 'null' year: anyOf: - "$ref": "#/$defs/Int" @@ -1088,6 +1098,7 @@ json_schema_version: 1 default: TeamSeason required: - record + - result - year - notes - count diff --git a/config/schema/artifacts_with_apollo/json_schemas_by_version/v1.yaml b/config/schema/artifacts_with_apollo/json_schemas_by_version/v1.yaml index 5b814f6ba..1f8944dbe 100644 --- a/config/schema/artifacts_with_apollo/json_schemas_by_version/v1.yaml +++ b/config/schema/artifacts_with_apollo/json_schemas_by_version/v1.yaml @@ -1040,6 +1040,12 @@ json_schema_version: 1 required: - x - "y" + SeasonResult: + type: string + enum: + - WON_CHAMPIONSHIP + - MADE_PLAYOFFS + - MISSED_PLAYOFFS Size: type: string enum: @@ -1395,6 +1401,13 @@ json_schema_version: 1 ElasticGraph: type: TeamRecord nameInIndex: the_record + result: + anyOf: + - "$ref": "#/$defs/SeasonResult" + - type: 'null' + ElasticGraph: + type: SeasonResult + nameInIndex: result year: anyOf: - "$ref": "#/$defs/Int" @@ -1466,6 +1479,7 @@ json_schema_version: 1 default: TeamSeason required: - record + - result - year - notes - count diff --git a/config/schema/artifacts_with_apollo/runtime_metadata.yaml b/config/schema/artifacts_with_apollo/runtime_metadata.yaml index 10fa483bf..f96e4d199 100644 --- a/config/schema/artifacts_with_apollo/runtime_metadata.yaml +++ b/config/schema/artifacts_with_apollo/runtime_metadata.yaml @@ -2162,6 +2162,8 @@ index_definitions_by_name: source: __self __counts.seasons_object|players_object|seasons_object|year: source: __self + __counts.seasons_object|result: + source: __self __counts.seasons_object|stadium_location: source: __self __counts.seasons_object|stadium_location|lat: @@ -2486,6 +2488,8 @@ index_definitions_by_name: source: __self nested_fields2.the_seasons.players_object.seasons_object.year: source: __self + nested_fields2.the_seasons.result: + source: __self nested_fields2.the_seasons.stadium_location.lat: source: __self nested_fields2.the_seasons.stadium_location.lon: @@ -2632,6 +2636,8 @@ index_definitions_by_name: source: __self seasons_nested.players_object.seasons_object.year: source: __self + seasons_nested.result: + source: __self seasons_nested.stadium_location.lat: source: __self seasons_nested.stadium_location.lon: @@ -2740,6 +2746,8 @@ index_definitions_by_name: source: __self seasons_object.players_object.seasons_object.year: source: __self + seasons_object.result: + source: __self seasons_object.stadium_location.lat: source: __self seasons_object.stadium_location.lon: @@ -2958,6 +2966,8 @@ index_definitions_by_name: source: __self the_nested_fields.the_seasons.players_object.seasons_object.year: source: __self + the_nested_fields.the_seasons.result: + source: __self the_nested_fields.the_seasons.stadium_location.lat: source: __self the_nested_fields.the_seasons.stadium_location.lon: @@ -6958,6 +6968,10 @@ object_types_by_name: resolver: name: object_without_lookahead graphql_only_return_type: true + SeasonResultListFilterInput: + graphql_fields_by_name: + count: + name_in_index: __counts SizeListFilterInput: graphql_fields_by_name: count: @@ -8015,6 +8029,9 @@ object_types_by_name: name_in_index: the_record resolver: name: get_record_field_value + result: + resolver: + name: get_record_field_value stadium_location: resolver: name: get_record_field_value @@ -8045,6 +8062,9 @@ object_types_by_name: name_in_index: the_record resolver: name: object_with_lookahead + result: + resolver: + name: object_with_lookahead stadium_location: resolver: name: object_with_lookahead @@ -8084,6 +8104,9 @@ object_types_by_name: name_in_index: the_record resolver: name: object_with_lookahead + result: + resolver: + name: object_with_lookahead stadium_location: resolver: name: object_with_lookahead @@ -8111,6 +8134,9 @@ object_types_by_name: players_object: resolver: name: get_record_field_value + result: + resolver: + name: get_record_field_value TeamSeasonListFilterInput: graphql_fields_by_name: count: diff --git a/config/schema/artifacts_with_apollo/schema.graphql b/config/schema/artifacts_with_apollo/schema.graphql index 4c12738e1..42a9f673d 100644 --- a/config/schema/artifacts_with_apollo/schema.graphql +++ b/config/schema/artifacts_with_apollo/schema.graphql @@ -12607,6 +12607,152 @@ type SearchHighlight @shareable { snippets: [String!]! } +enum SeasonResult { + MADE_PLAYOFFS + MISSED_PLAYOFFS + WON_CHAMPIONSHIP +} + +""" +Input type used to specify filters on `SeasonResult` fields. + +Will match all documents if passed as an empty object (or as `null`). +""" +input SeasonResultFilterInput { + """ + Matches records where all of the provided sub-filters evaluate to true. This works just like an AND operator in SQL. + + Note: multiple filters are automatically ANDed together. This is only needed when you have multiple filters that can't + be provided on a single `SeasonResultFilterInput` input because of collisions + between key names. For example, if you want to AND multiple + OR'd sub-filters (the equivalent of (A OR B) AND (C OR D)), you could do all_of: [{any_of: [...]}, {any_of: [...]}]. + + When `null` or an empty list is passed, matches all documents. + """ + all_of: [SeasonResultFilterInput!] + + """ + Matches records where any of the provided sub-filters evaluate to true. + This works just like an OR operator in SQL. + + When `null` is passed, matches all documents. + When an empty list is passed, this part of the filter matches no documents. + """ + any_of: [SeasonResultFilterInput!] + + """ + Matches records where the field value is equal to any of the provided values. + This works just like an IN operator in SQL. + + When `null` is passed, matches all documents. When an empty list is passed, + this part of the filter matches no documents. When `null` is passed in the + list, this part of the filter matches records where the field value is `null`. + """ + equal_to_any_of: [SeasonResultInput] + + """ + Matches records where the provided sub-filter evaluates to false. + This works just like a NOT operator in SQL. + + When `null` or an empty object is passed, matches no documents. + """ + not: SeasonResultFilterInput +} + +enum SeasonResultInput { + MADE_PLAYOFFS + MISSED_PLAYOFFS + WON_CHAMPIONSHIP +} + +""" +Input type used to specify filters on elements of a `[SeasonResult]` field. + +Will match all documents if passed as an empty object (or as `null`). +""" +input SeasonResultListElementFilterInput { + """ + Matches records where all of the provided sub-filters evaluate to true. This works just like an AND operator in SQL. + + Note: multiple filters are automatically ANDed together. This is only needed when you have multiple filters that can't + be provided on a single `SeasonResultListElementFilterInput` input because of + collisions between key names. For example, if you want to AND multiple + OR'd sub-filters (the equivalent of (A OR B) AND (C OR D)), you could do all_of: [{any_of: [...]}, {any_of: [...]}]. + + When `null` or an empty list is passed, matches all documents. + """ + all_of: [SeasonResultListElementFilterInput!] + + """ + Matches records where any of the provided sub-filters evaluate to true. + This works just like an OR operator in SQL. + + When `null` is passed, matches all documents. + When an empty list is passed, this part of the filter matches no documents. + """ + any_of: [SeasonResultListElementFilterInput!] + + """ + Matches records where the field value is equal to any of the provided values. + This works just like an IN operator in SQL. + + When `null` is passed, matches all documents. When an empty list is passed, + this part of the filter matches no documents. When `null` is passed in the + list, this part of the filter matches records where the field value is `null`. + """ + equal_to_any_of: [SeasonResultInput!] +} + +""" +Input type used to specify filters on `[SeasonResult]` fields. + +Will match all documents if passed as an empty object (or as `null`). +""" +input SeasonResultListFilterInput { + """ + Matches records where all of the provided sub-filters evaluate to true. This works just like an AND operator in SQL. + + Note: multiple filters are automatically ANDed together. This is only needed when you have multiple filters that can't + be provided on a single `SeasonResultListFilterInput` input because of + collisions between key names. For example, if you want to AND multiple + OR'd sub-filters (the equivalent of (A OR B) AND (C OR D)), you could do all_of: [{any_of: [...]}, {any_of: [...]}]. + + When `null` or an empty list is passed, matches all documents. + """ + all_of: [SeasonResultListFilterInput!] + + """ + Matches records where any of the provided sub-filters evaluate to true. + This works just like an OR operator in SQL. + + When `null` is passed, matches all documents. + When an empty list is passed, this part of the filter matches no documents. + """ + any_of: [SeasonResultListFilterInput!] + + """ + Matches records where any of the list elements match the provided sub-filter. + + When `null` or an empty object is passed, matches all documents. + """ + any_satisfy: SeasonResultListElementFilterInput + + """ + Used to filter on the number of non-null elements in this list field. + + When `null` or an empty object is passed, matches all documents. + """ + count: IntFilterInput + + """ + Matches records where the provided sub-filter evaluates to false. + This works just like a NOT operator in SQL. + + When `null` or an empty object is passed, matches no documents. + """ + not: SeasonResultListFilterInput +} + enum Size { LARGE MEDIUM @@ -15551,6 +15697,7 @@ type TeamSeason { players_nested: [Player!]! players_object: [Player!]! record: TeamRecord + result: SeasonResult stadium_location: GeoLocation started_at: DateTime was_shortened: Boolean @@ -15582,6 +15729,11 @@ type TeamSeasonAggregatedValues { """ record: TeamRecordAggregatedValues + """ + Computed aggregate values for the `result` field. + """ + result: NonNumericAggregatedValues + """ Computed aggregate values for the `stadium_location` field. """ @@ -15680,6 +15832,13 @@ input TeamSeasonFieldsListFilterInput { """ record: TeamRecordFieldsListFilterInput + """ + Used to filter on the `result` field. + + When `null` or an empty object is passed, matches all documents. + """ + result: SeasonResultListFilterInput + """ Used to filter on the `stadium_location` field. @@ -15786,6 +15945,13 @@ input TeamSeasonFilterInput { """ record: TeamRecordFilterInput + """ + Used to filter on the `result` field. + + When `null` or an empty object is passed, matches all documents. + """ + result: SeasonResultFilterInput + """ Used to filter on the `stadium_location` field. @@ -15859,6 +16025,11 @@ type TeamSeasonGroupedBy { """ record: TeamRecordGroupedBy + """ + The `result` field value for this group. + """ + result: SeasonResult + """ Offers the different grouping options for the `stadium_location` value within this group. """ @@ -15909,6 +16080,11 @@ type TeamSeasonHighlights { Search highlights for the `players_object`, providing snippets of the matching text. """ players_object: PlayerHighlights + + """ + Search highlights for the `result`, providing snippets of the matching text. + """ + result: [String!]! } """ diff --git a/config/schema/artifacts_with_apollo/schema.proto b/config/schema/artifacts_with_apollo/schema.proto index a996522af..bdf310543 100644 --- a/config/schema/artifacts_with_apollo/schema.proto +++ b/config/schema/artifacts_with_apollo/schema.proto @@ -258,6 +258,16 @@ message Position { optional double y = 2; } +enum SeasonResult { + // The default value when no enum value has been explicitly set. Do not use this value. + // See https://protobuf.dev/programming-guides/proto3/#enum-default. + SEASON_RESULT_UNSPECIFIED = 0; + + SEASON_RESULT_WON_CHAMPIONSHIP = 1; + SEASON_RESULT_MADE_PLAYOFFS = 2; + SEASON_RESULT_MISSED_PLAYOFFS = 3; +} + enum Size { // The default value when no enum value has been explicitly set. Do not use this value. // See https://protobuf.dev/programming-guides/proto3/#enum-default. @@ -333,6 +343,7 @@ message TeamRecord { message TeamSeason { optional .elasticgraph.TeamRecord record = 1; + optional .elasticgraph.SeasonResult result = 11; optional int32 year = 2; repeated string notes = 3; optional int32 count = 4; diff --git a/config/schema/teams.rb b/config/schema/teams.rb index 77e581827..7f93256e5 100644 --- a/config/schema/teams.rb +++ b/config/schema/teams.rb @@ -133,8 +133,13 @@ t.field "first_win_on", "Date" end + schema.enum_type "SeasonResult" do |t| + t.values "WON_CHAMPIONSHIP", "MADE_PLAYOFFS", "MISSED_PLAYOFFS" + end + schema.object_type "TeamSeason" do |t| t.field "record", "TeamRecord", name_in_index: "the_record" + t.field "result", "SeasonResult" t.field "year", "Int" t.field "notes", "[String!]!", singular: "note" # `details.count` isn't really meaningful on our team model here, but we need this field diff --git a/elasticgraph-apollo/spec/integration/elastic_graph/apollo/graphql/apollo_entity_ref_resolver_spec.rb b/elasticgraph-apollo/spec/integration/elastic_graph/apollo/graphql/apollo_entity_ref_resolver_spec.rb index 87d3b186f..a3367ac9c 100644 --- a/elasticgraph-apollo/spec/integration/elastic_graph/apollo/graphql/apollo_entity_ref_resolver_spec.rb +++ b/elasticgraph-apollo/spec/integration/elastic_graph/apollo/graphql/apollo_entity_ref_resolver_spec.rb @@ -66,7 +66,7 @@ module GraphQL ) end - it "groups by an entity ref field in a sub-aggregation, including a group for the missing id" do + it "groups by an entity ref field in a sub-aggregation, including a group for the missing id", :expect_missing_aggregations do sponsorship = ->(sponsor_id) { build(:sponsorship, sponsor_id: sponsor_id) } players = ->(*sponsor_ids) { [build(:player, affiliations: build(:affiliations, sponsorships: sponsor_ids.map(&sponsorship)))] } index_records( @@ -104,6 +104,7 @@ module GraphQL {"grouped_by" => {"the_sponsor" => {"id" => "s2"}}, "count_detail" => {"approximate_value" => 1}}, {"grouped_by" => {"the_sponsor" => nil}, "count_detail" => {"approximate_value" => 1}} ) + expect_last_query_to_use_missing_aggregations_on(["current_players_nested.affiliations.sponsorships_nested.sponsor_id"]) end it "groups list entity references on individual ids without counting duplicate ids twice per document" do diff --git a/elasticgraph-graphql/spec/acceptance/hidden_types_spec.rb b/elasticgraph-graphql/spec/acceptance/hidden_types_spec.rb index 76329ad27..75a558551 100644 --- a/elasticgraph-graphql/spec/acceptance/hidden_types_spec.rb +++ b/elasticgraph-graphql/spec/acceptance/hidden_types_spec.rb @@ -95,6 +95,7 @@ module ElasticGraph type_and_filters_for("Untyped") + type_and_filters_for("LongString") + type_and_filters_for("Material", as_input_enum: true) + + type_and_filters_for("SeasonResult", include_list: true, as_input_enum: true) + type_and_filters_for("Size", include_list: true, as_input_enum: true) + type_and_filters_for("TeamNestedFields") + ["TeamNestedFieldsHighlights"] + type_and_filters_for("Affiliations") + diff --git a/elasticgraph-graphql/spec/acceptance/sub_aggregations_spec.rb b/elasticgraph-graphql/spec/acceptance/sub_aggregations_spec.rb index c16d43658..ac8694cc5 100644 --- a/elasticgraph-graphql/spec/acceptance/sub_aggregations_spec.rb +++ b/elasticgraph-graphql/spec/acceptance/sub_aggregations_spec.rb @@ -41,7 +41,7 @@ module ElasticGraph expect(indexed_counts_from(team_seasons_nodes)).to eq({}) end - it "supports arbitrarily deeply nested sub-aggregations", :expect_search_routing, :expect_index_exclusions do + it "supports arbitrarily deeply nested sub-aggregations", :expect_search_routing, :expect_index_exclusions, :expect_missing_aggregations do index_data test_ungrouped_sub_aggregations test_grouped_sub_aggregations @@ -55,7 +55,7 @@ def index_data current_players: [build(:player, name: "Bob")], formed_on: "1903-01-01", seasons: [ - build(:team_season, year: 2020, was_shortened: true, record: build(:team_record, wins: 50, losses: 12, first_win_on: "2020-03-02", last_win_on: "2020-11-12"), notes: ["pandemic", "shortened"], started_at: "2020-01-15T12:02:20Z", stadium_location: yankee_stadium, players: [ + build(:team_season, year: 2020, result: "WON_CHAMPIONSHIP", was_shortened: true, record: build(:team_record, wins: 50, losses: 12, first_win_on: "2020-03-02", last_win_on: "2020-11-12"), notes: ["pandemic", "shortened"], started_at: "2020-01-15T12:02:20Z", stadium_location: yankee_stadium, players: [ build(:player, name: "Ted", seasons: [build(:player_season, year: 2018, games_played: 20), build(:player_season, year: 2018, games_played: 30)]), build(:player, name: "Dave", seasons: [build(:player_season, year: 2022, games_played: 10)]) ]) @@ -67,10 +67,10 @@ def index_data formed_on: "1883-01-01", current_players: [build(:player, name: "Kat", seasons: []), build(:player, name: "Sue", seasons: [])], seasons: [ - build(:team_season, year: 2020, was_shortened: true, record: build(:team_record, wins: 30, losses: 22, first_win_on: "2020-05-02", last_win_on: "2020-12-12"), notes: ["pandemic", "covid"], started_at: "2020-01-15T12:02:20Z", stadium_location: dodger_stadium, players: []), - build(:team_season, year: 2021, was_shortened: false, record: build(:team_record, wins: nil, losses: 22, first_win_on: nil, last_win_on: "2021-12-12"), notes: [], started_at: "2021-02-16T13:03:30Z", stadium_location: nil, players: []), - build(:team_season, year: 2022, was_shortened: false, record: build(:team_record, wins: 40, losses: 15, first_win_on: "2022-06-02", last_win_on: "2022-08-12"), notes: [], started_at: "2022-03-17T14:04:40Z", stadium_location: dodger_stadium, players: []), - build(:team_season, year: 2023, was_shortened: false, record: build(:team_record, wins: 50, losses: nil, first_win_on: "2023-01-06", last_win_on: nil), notes: [], started_at: "2023-04-18T12:02:59Z", stadium_location: dodger_stadium, players: []) + build(:team_season, year: 2020, result: "MADE_PLAYOFFS", was_shortened: true, record: build(:team_record, wins: 30, losses: 22, first_win_on: "2020-05-02", last_win_on: "2020-12-12"), notes: ["pandemic", "covid"], started_at: "2020-01-15T12:02:20Z", stadium_location: dodger_stadium, players: []), + build(:team_season, year: 2021, result: nil, was_shortened: false, record: build(:team_record, wins: nil, losses: 22, first_win_on: nil, last_win_on: "2021-12-12"), notes: [], started_at: "2021-02-16T13:03:30Z", stadium_location: nil, players: []), + build(:team_season, year: 2022, result: "MADE_PLAYOFFS", was_shortened: false, record: build(:team_record, wins: 40, losses: 15, first_win_on: "2022-06-02", last_win_on: "2022-08-12"), notes: [], started_at: "2022-03-17T14:04:40Z", stadium_location: dodger_stadium, players: []), + build(:team_season, year: 2023, result: "MISSED_PLAYOFFS", was_shortened: false, record: build(:team_record, wins: 50, losses: nil, first_win_on: "2023-01-06", last_win_on: nil), notes: [], started_at: "2023-04-18T12:02:59Z", stadium_location: dodger_stadium, players: []) ] ), build( @@ -79,7 +79,7 @@ def index_data formed_on: "1901-01-01", current_players: [build(:player, name: "Ed", seasons: []), build(:player, name: "Ty", seasons: [])], seasons: [ - build(:team_season, year: 2019, was_shortened: false, record: build(:team_record, wins: 40, losses: 7, first_win_on: "2019-04-02", last_win_on: "2019-07-12"), notes: ["old rules"], started_at: "2019-01-15T12:02:20Z", stadium_location: fenway_park, players: []) + build(:team_season, year: 2019, result: "MISSED_PLAYOFFS", was_shortened: false, record: build(:team_record, wins: 40, losses: 7, first_win_on: "2019-04-02", last_win_on: "2019-07-12"), notes: ["old rules"], started_at: "2019-01-15T12:02:20Z", stadium_location: fenway_park, players: []) ] ), build( @@ -195,6 +195,7 @@ def test_grouped_sub_aggregations {"year" => 2022} => count_detail_of(1), {"year" => 2023} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([]) # Test a simple sub-aggregation grouping of one Boolean `terms` field team_seasons_nodes = aggregate_season_counts_grouped_by("was_shortened") @@ -202,6 +203,17 @@ def test_grouped_sub_aggregations {case_correctly("was_shortened") => true} => count_detail_of(2), {case_correctly("was_shortened") => false} => count_detail_of(4) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.was_shortened")]) + + # Test a simple sub-aggregation grouping of one enum `terms` field + team_seasons_nodes = aggregate_season_counts_grouped_by("result") + expect(indexed_counts_from(team_seasons_nodes)).to eq({ + {"result" => enum_value("WON_CHAMPIONSHIP")} => count_detail_of(1), + {"result" => enum_value("MADE_PLAYOFFS")} => count_detail_of(2), + {"result" => enum_value("MISSED_PLAYOFFS")} => count_detail_of(2), + {"result" => nil} => count_detail_of(1) + }) + expect_last_query_to_use_non_composite_missing_aggregations_on([]) # Test what happens if all grouped by fields are excluded via a directive. team_seasons_nodes = aggregate_season_counts_grouped_by("year @include(if: false)", "note @skip(if: true)") @@ -228,6 +240,7 @@ def test_grouped_sub_aggregations {"year" => 2022, "note" => nil} => count_detail_of(1), {"year" => 2023, "note" => nil} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([]) verify_filtered_sub_aggregations_with_grouped_by @@ -241,6 +254,7 @@ def test_grouped_sub_aggregations {"record" => {case_correctly("first_win_on") => {case_correctly("as_date") => "2023-01-01"}, case_correctly("last_win_on") => {case_correctly("as_date") => nil}}} => count_detail_of(1), {"record" => {case_correctly("first_win_on") => {case_correctly("as_date") => nil}, case_correctly("last_win_on") => {case_correctly("as_date") => "2021-12-01"}}} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.the_record.first_win_on"), case_correctly("seasons_nested.the_record.last_win_date")]) # Group on sub-fields of an object, some date fields, and some fields with alternate `name_in_index`. team_seasons_nodes = aggregate_season_counts_grouped_by("record { wins, last_win_on { as_date(truncation_unit: MONTH) }, first_win_on { as_date(truncation_unit: MONTH) }}") @@ -252,6 +266,7 @@ def test_grouped_sub_aggregations {"record" => {case_correctly("first_win_on") => {case_correctly("as_date") => "2023-01-01"}, case_correctly("last_win_on") => {case_correctly("as_date") => nil}, "wins" => 50}} => count_detail_of(1), {"record" => {case_correctly("first_win_on") => {case_correctly("as_date") => nil}, case_correctly("last_win_on") => {case_correctly("as_date") => "2021-12-01"}, "wins" => nil}} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.the_record.first_win_on"), case_correctly("seasons_nested.the_record.last_win_date")]) # Test using groupings on sibling and deeply nested sub-aggs. verify_aggregate_sibling_and_deeply_nested_grouped_counts_and_aggregated_values @@ -293,6 +308,7 @@ def test_grouped_sub_aggregations {case_correctly("started_at") => {case_correctly("as_date_time") => "2022-03-17T00:00:00.000Z"}} => count_detail_of(1), {case_correctly("started_at") => {case_correctly("as_date_time") => "2023-04-18T00:00:00.000Z"}} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.started_at")]) # DateTime: as_date() team_seasons_nodes = aggregate_season_counts_grouped_by("started_at {as_date(truncation_unit: MONTH)}") @@ -311,6 +327,7 @@ def test_grouped_sub_aggregations {case_correctly("started_at") => {case_correctly("as_day_of_week") => enum_value("WEDNESDAY")}} => count_detail_of(2), {case_correctly("started_at") => {case_correctly("as_day_of_week") => enum_value("THURSDAY")}} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.started_at")]) # DateTime: as_time_of_day() truncated to SECOND team_seasons_nodes = aggregate_season_counts_grouped_by("started_at {as_time_of_day(truncation_unit: SECOND)}") @@ -320,6 +337,7 @@ def test_grouped_sub_aggregations {case_correctly("started_at") => {case_correctly("as_time_of_day") => "13:03:30"}} => count_detail_of(1), {case_correctly("started_at") => {case_correctly("as_time_of_day") => "14:04:40"}} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.started_at")]) # DateTime: as_time_of_day() truncated to MINUTE team_seasons_nodes = aggregate_season_counts_grouped_by("started_at {as_time_of_day(truncation_unit: MINUTE)}") @@ -357,6 +375,7 @@ def test_grouped_sub_aggregations {"record" => {case_correctly("last_win_on") => {case_correctly("as_day_of_week") => enum_value("SUNDAY")}}} => count_detail_of(1), {"record" => {case_correctly("last_win_on") => {case_correctly("as_day_of_week") => nil}}} => count_detail_of(1) }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.the_record.last_win_date")]) verify_geo_tile_sub_aggregations test_optimizable_aggregations_with_sub_aggregations @@ -376,6 +395,11 @@ def test_grouped_sub_aggregations context "when sub-aggregations use the `CompositeGroupingAdapter`" do include_examples "sub-aggregation acceptance" + # The `composite` aggregation handles missing values with its `missing_bucket` option instead. + def expect_last_query_to_use_non_composite_missing_aggregations_on(_field_paths) + expect_last_query_to_use_missing_aggregations_on([]) + end + def build_graphql(**options) super( sub_aggregation_grouping_adapter: GraphQL::Aggregation::CompositeGroupingAdapter, @@ -422,6 +446,10 @@ def verify_aggregate_sibling_and_deeply_nested_grouped_counts_and_aggregated_val context "when sub-aggregations use the `NonCompositeGroupingAdapter`" do include_examples "sub-aggregation acceptance" + def expect_last_query_to_use_non_composite_missing_aggregations_on(field_paths) + expect_last_query_to_use_missing_aggregations_on(field_paths) + end + def build_graphql(**options) super( sub_aggregation_grouping_adapter: GraphQL::Aggregation::NonCompositeGroupingAdapter, @@ -481,6 +509,7 @@ def verify_geo_tile_sub_aggregations stadium_tile([75, 96]) => count_detail_of(1), # Yankee Stadium stadium_tile([77, 94]) => count_detail_of(1) # Fenway Park }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.stadium_location")]) # Zoom level 2 has a 4x4 grid of tiles, so Yankee Stadium and Fenway Park are in the same tile. team_seasons_nodes = aggregate_season_counts_grouped_by("stadium_location { as_geo_tile(zoom_level: 2) { x y } }") @@ -518,6 +547,7 @@ def verify_geo_tile_sub_aggregations {case_correctly("was_shortened") => false, **stadium_tile([0, 1])} => count_detail_of(2), # Dodgers 2022 and 2023 {case_correctly("was_shortened") => false, **stadium_tile([1, 1])} => count_detail_of(1) # Red Sox 2019 }) + expect_last_query_to_use_non_composite_missing_aggregations_on([case_correctly("seasons_nested.stadium_location"), case_correctly("seasons_nested.was_shortened")]) # Use the default zoom level (7). team_seasons_nodes = aggregate_season_counts_grouped_by("stadium_location { as_geo_tile { zoom_level x y } }", team_aggregations_args: {filter: {current_name: {equal_to_any_of: ["Red Sox"]}}}) diff --git a/elasticgraph-graphql/spec/integration/elastic_graph/graphql/datastore_query/sub_aggregations_spec.rb b/elasticgraph-graphql/spec/integration/elastic_graph/graphql/datastore_query/sub_aggregations_spec.rb index 8d6bc0188..32bb5551c 100644 --- a/elasticgraph-graphql/spec/integration/elastic_graph/graphql/datastore_query/sub_aggregations_spec.rb +++ b/elasticgraph-graphql/spec/integration/elastic_graph/graphql/datastore_query/sub_aggregations_spec.rb @@ -602,7 +602,7 @@ class GraphQL expect(results).to eq([{"doc_count" => 0, "key" => {}}]) end - it "can group sub-aggregations on a single date field" do + it "can group sub-aggregations on a single date field", :expect_missing_aggregations do query = aggregation_query_of(name: "teams", sub_aggregations: [ nested_sub_aggregation_of(path_in_index: ["seasons_nested"], query: sub_aggregation_query_of(name: "seasons_nested", groupings: [ date_histogram_grouping_of("seasons_nested", "started_at", "year") @@ -627,9 +627,11 @@ class GraphQL } }.with_missing_value_bucket(0) }]) + + expect_last_query_to_use_missing_aggregations_on(["seasons_nested.started_at"]) end - it "can group sub-aggregations on multiple date fields" do + it "can group sub-aggregations on multiple date fields", :expect_missing_aggregations do query = aggregation_query_of(name: "teams", sub_aggregations: [ nested_sub_aggregation_of(path_in_index: ["seasons_nested"], query: sub_aggregation_query_of(name: "seasons_nested", groupings: [ date_histogram_grouping_of("seasons_nested", "started_at", "year"), @@ -667,9 +669,11 @@ class GraphQL "buckets" => [] }}.with_missing_value_bucket(0)) }]) + + expect_last_query_to_use_missing_aggregations_on(["seasons_nested.started_at", "seasons_nested.won_games_at"]) end - it "can group sub-aggregations on a single non-date field and a single date field" do + it "can group sub-aggregations on a single non-date field and a single date field", :expect_missing_aggregations do query = aggregation_query_of(name: "teams", sub_aggregations: [ nested_sub_aggregation_of(path_in_index: ["seasons_nested"], query: sub_aggregation_query_of(name: "seasons_nested", groupings: [ date_histogram_grouping_of("seasons_nested", "started_at", "year"), @@ -722,9 +726,11 @@ class GraphQL "buckets" => [] }}) }]) + + expect_last_query_to_use_missing_aggregations_on(["seasons_nested.started_at"]) end - it "can group sub-aggregations on multiple non-date fields and a single date field" do + it "can group sub-aggregations on multiple non-date fields and a single date field", :expect_missing_aggregations do query = aggregation_query_of(name: "teams", sub_aggregations: [ nested_sub_aggregation_of(path_in_index: ["seasons_nested"], query: sub_aggregation_query_of(name: "seasons_nested", groupings: [ date_histogram_grouping_of("seasons_nested", "started_at", "year"), @@ -799,9 +805,11 @@ class GraphQL "buckets" => [] }}) }]) + + expect_last_query_to_use_missing_aggregations_on(["seasons_nested.started_at"]) end - it "can group sub-aggregations on multiple non-date fields and multiple date fields" do + it "can group sub-aggregations on multiple non-date fields and multiple date fields", :expect_missing_aggregations do query = aggregation_query_of(name: "teams", sub_aggregations: [ nested_sub_aggregation_of(path_in_index: ["seasons_nested"], query: sub_aggregation_query_of(name: "seasons_nested", groupings: [ date_histogram_grouping_of("seasons_nested", "started_at", "year"), @@ -910,6 +918,8 @@ class GraphQL "buckets" => [] }})) }]) + + expect_last_query_to_use_missing_aggregations_on(["seasons_nested.started_at", "seasons_nested.won_games_at"]) end it "accounts for an extra filtering layer in the `buckets_path` meta" do @@ -945,7 +955,7 @@ class GraphQL }]) end - it "ignores date histogram buckets that have no documents in them" do + it "ignores date histogram buckets that have no documents in them", :expect_missing_aggregations do index_into( graphql, build( @@ -971,6 +981,8 @@ class GraphQL date_histogram_bucket(2021, 1), date_histogram_bucket(2022, 2) ]) + + expect_last_query_to_use_missing_aggregations_on(["seasons_nested.started_at"]) end it "gets `doc_count_error_upper_bound` based on the `needs_doc_count_error` query flag" do diff --git a/elasticgraph-indexer/spec/acceptance/list_fields_spec.rb b/elasticgraph-indexer/spec/acceptance/list_fields_spec.rb index 3b0c27cf2..f09dcd0cc 100644 --- a/elasticgraph-indexer/spec/acceptance/list_fields_spec.rb +++ b/elasticgraph-indexer/spec/acceptance/list_fields_spec.rb @@ -105,6 +105,7 @@ module ElasticGraph "seasons_object|players_object|seasons_object|awards" => 3, "seasons_object|players_object|seasons_object|games_played" => 3, "seasons_object|players_object|seasons_object|year" => 3, + "seasons_object|result" => 2, "seasons_object|stadium_location" => 2, "seasons_object|stadium_location|lat" => 0, "seasons_object|stadium_location|lon" => 0, diff --git a/spec_support/lib/elastic_graph/spec_support/factories/teams.rb b/spec_support/lib/elastic_graph/spec_support/factories/teams.rb index f978bfb87..be3a20745 100644 --- a/spec_support/lib/elastic_graph/spec_support/factories/teams.rb +++ b/spec_support/lib/elastic_graph/spec_support/factories/teams.rb @@ -175,6 +175,7 @@ year { Faker::Number.between(from: 1950, to: 2023) } record { build :team_record } was_shortened { false } + result { Faker::Base.sample(["WON_CHAMPIONSHIP", "MADE_PLAYOFFS", "MISSED_PLAYOFFS"]) } stadium_location { build :geo_location } notes do diff --git a/spec_support/lib/elastic_graph/spec_support/uses_datastore.rb b/spec_support/lib/elastic_graph/spec_support/uses_datastore.rb index c8343fcd4..d02ac854b 100644 --- a/spec_support/lib/elastic_graph/spec_support/uses_datastore.rb +++ b/spec_support/lib/elastic_graph/spec_support/uses_datastore.rb @@ -236,6 +236,23 @@ def indices_excluded_from_searches(cluster_name) end end + # Returns, for each performed search, the sorted field paths that have a `missing` aggregation. A grouping without + # a missing value placeholder needs a `missing` aggregation alongside its `terms` aggregation, at every sub-aggregation + # level. That makes the number of aggregations grow exponentially with the number of such groupings. + def missing_aggregation_field_paths_from_queries(cluster_name) + datastore_msearch_requests(cluster_name).flat_map do |req| + req.body.split("\n").each_slice(2).map do |_header_line, body_line| + missing_aggregation_field_paths_in(JSON.parse(body_line)["aggs"]).uniq.sort + end + end + end + + def missing_aggregation_field_paths_in(aggs) + (aggs || {}).values.flat_map do |clause| + [clause.dig("missing", "field"), *missing_aggregation_field_paths_in(clause["aggs"])].compact + end + end + def unrefreshed_bulk_calls(cluster_name) datastore_write_requests(cluster_name) .select { |req| req.url.path == "/_bulk" } @@ -282,6 +299,16 @@ def unrefreshed_bulk_calls(cluster_name) expect(indices_excluded_from_searches("other3").flatten).to eq [] end + # `missing` aggregations make the number of aggregations grow exponentially (see `missing_aggregation_field_paths_from_queries`), + # so tests that expect them must be tagged with `:expect_missing_aggregations` and should use + # `expect_last_query_to_use_missing_aggregations_on` to specify which field paths get them. + unless ex.metadata[:expect_missing_aggregations] + expect(missing_aggregation_field_paths_from_queries("main").flatten).to eq [] + expect(missing_aggregation_field_paths_from_queries("other1").flatten).to eq [] + expect(missing_aggregation_field_paths_from_queries("other2").flatten).to eq [] + expect(missing_aggregation_field_paths_from_queries("other3").flatten).to eq [] + end + # Verify that all queries specify what indices to search. If the index search expression is `""`, # the datastore will search ALL indices which is undesirable. expect(index_search_expressions_from_queries("main")).to exclude("") @@ -396,6 +423,10 @@ def expect_to_have_excluded_indices(cluster_name, *excluded_indices_for_last_n_q expect(indices_excluded_from_searches(cluster_name).last(excluded_indices_for_last_n_queries.size)).to eq(excluded_indices_for_last_n_queries) end + def expect_last_query_to_use_missing_aggregations_on(field_paths) + expect(missing_aggregation_field_paths_from_queries("main").last(1)).to eq([field_paths]) + end + def make_datastore_calls(cluster_name, *methods_and_paths) datastore_requests(cluster_name).clear change { datastore_requests(cluster_name).map(&:description) }.from([])