Skip to content

Commit c845040

Browse files
Support nested sourced_from fields end-to-end (#1252)
## Summary Completes the nested `sourced_from` feature by wiring up the indexing-time piece: the `update_index_data.painless` script now resolves `sourced_from` fields onto nested elements of an indexed document, not just top-level fields. This is the final PR in the nested `sourced_from` series (building on the runtime-metadata, relationship-chain, and update-target resolution PRs already merged to main). ## What's included - Painless script (`index_data.painless`) — nested-apply logic: buffers each related event's sourced fields in `__nested_sourced_data` keyed by a per-element key, then re-applies them onto the target nested element on every event (so a later self-event that overwrites the nested array doesn't drop sourced fields). Handles out-of-order ingestion, list and object path segments, and multi-byte element ids via a length-prefixed key encoding. - One key keys both `__versions` and `__nested_sourced_data`; top-level events keep a bare relationship key so existing documents stay byte-identical and version-recovery is unchanged. - Param threading — `update.rb` passes the registered nested-path config (`sourcedFromNestedPaths`, `sourcedFromNestedPathIdentifiers`, `sourcedFromNestedFields`) through to the script. - `__nested_sourced_data` mapping — added to every index (internal_fields), mirroring `__versions`. - Test schema — `config/schema/teams.rb` gains a `Team → staff.coaches[]/general_manager → *Profile` shape exercising nested `sourced_from` over both list and singleton-object path segments, with distinct source types. - Tests — new `nested_multi_source_indexing_spec.rb` acceptance coverage (out-of-order, root re-index, stale event, relationship-mutation rejection, multi-byte ids, all-object + list paths); factories for the new types; unit coverage for the threaded params and the relationship-name guarantee the codec relies on. ## Deferred - Schema-dump-time validation rejecting nested `sourced_from` on list/__counts fields (not yet supported) — separate PR. - Pruning of orphaned `__nested_sourced_data` entries and detection of nested-element re-targeting — tracked as known limitations.
1 parent 4545482 commit c845040

30 files changed

Lines changed: 9142 additions & 3095 deletions

File tree

‎config/schema/artifacts/data_warehouse.yaml‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ tables:
1414
shapes ARRAY<STRUCT<type STRING, coordinates ARRAY<FLOAT>>>,
1515
manufacturer_id STRING
1616
)
17+
coach_profiles:
18+
table_schema: |-
19+
CREATE TABLE IF NOT EXISTS coach_profiles (
20+
id STRING,
21+
team_id STRING,
22+
coach_id STRING,
23+
annual_salary INT,
24+
team_league STRING,
25+
team_formed_on DATE
26+
)
1727
components:
1828
table_schema: |-
1929
CREATE TABLE IF NOT EXISTS components (
@@ -49,6 +59,15 @@ tables:
4959
voltage INT,
5060
manufacturer_id STRING
5161
)
62+
general_manager_profiles:
63+
table_schema: |-
64+
CREATE TABLE IF NOT EXISTS general_manager_profiles (
65+
id STRING,
66+
team_id STRING,
67+
annual_salary INT,
68+
team_league STRING,
69+
team_formed_on DATE
70+
)
5271
manufacturers:
5372
table_schema: |-
5473
CREATE TABLE IF NOT EXISTS manufacturers (
@@ -108,7 +127,8 @@ tables:
108127
seasons_nested ARRAY<STRUCT<the_record STRUCT<win_count INT, loss_count INT, last_win_date DATE, first_win_on DATE>, year INT, notes ARRAY<STRING>, count INT, started_at TIMESTAMP, won_games_at ARRAY<TIMESTAMP>, was_shortened BOOLEAN, players_nested ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, players_object ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>>>,
109128
seasons_object ARRAY<STRUCT<the_record STRUCT<win_count INT, loss_count INT, last_win_date DATE, first_win_on DATE>, year INT, notes ARRAY<STRING>, count INT, started_at TIMESTAMP, won_games_at ARRAY<TIMESTAMP>, was_shortened BOOLEAN, players_nested ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, players_object ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>>>,
110129
the_nested_fields STRUCT<forbes_valuation_moneys ARRAY<STRUCT<currency STRING, amount_cents INT>>, current_players ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, the_seasons ARRAY<STRUCT<the_record STRUCT<win_count INT, loss_count INT, last_win_date DATE, first_win_on DATE>, year INT, notes ARRAY<STRING>, count INT, started_at TIMESTAMP, won_games_at ARRAY<TIMESTAMP>, was_shortened BOOLEAN, players_nested ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, players_object ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>>>>,
111-
nested_fields2 STRUCT<forbes_valuation_moneys ARRAY<STRUCT<currency STRING, amount_cents INT>>, current_players ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, the_seasons ARRAY<STRUCT<the_record STRUCT<win_count INT, loss_count INT, last_win_date DATE, first_win_on DATE>, year INT, notes ARRAY<STRING>, count INT, started_at TIMESTAMP, won_games_at ARRAY<TIMESTAMP>, was_shortened BOOLEAN, players_nested ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, players_object ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>>>>
130+
nested_fields2 STRUCT<forbes_valuation_moneys ARRAY<STRUCT<currency STRING, amount_cents INT>>, current_players ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, the_seasons ARRAY<STRUCT<the_record STRUCT<win_count INT, loss_count INT, last_win_date DATE, first_win_on DATE>, year INT, notes ARRAY<STRING>, count INT, started_at TIMESTAMP, won_games_at ARRAY<TIMESTAMP>, was_shortened BOOLEAN, players_nested ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>, players_object ARRAY<STRUCT<name STRING, nicknames ARRAY<STRING>, affiliations STRUCT<sponsorships_nested ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>, sponsorships_object ARRAY<STRUCT<sponsor_id STRING, annual_total STRUCT<currency STRING, amount_cents INT>>>>, seasons_nested ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>, seasons_object ARRAY<STRUCT<year INT, games_played INT, awards ARRAY<STRING>>>>>>>>,
131+
staff STRUCT<coaches ARRAY<STRUCT<id STRING, name STRING, salary INT>>, general_manager STRUCT<id STRING, name STRING, salary INT>>
112132
)
113133
widget_currencies:
114134
table_schema: |-

0 commit comments

Comments
 (0)