Skip to content

Support nested sourced_from fields end-to-end - #1252

Merged
ellisandrews-toast merged 11 commits into
mainfrom
nested-sourced-from-script-and-acceptance
Jun 29, 2026
Merged

Support nested sourced_from fields end-to-end#1252
ellisandrews-toast merged 11 commits into
mainfrom
nested-sourced-from-script-and-acceptance

Conversation

@ellisandrews-toast

@ellisandrews-toast ellisandrews-toast commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

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.

@myronmarston
myronmarston changed the base branch from main to myron/nested-sourced-from-prep June 12, 2026 22:35
@myronmarston
myronmarston force-pushed the nested-sourced-from-script-and-acceptance branch from f4549d9 to 4e853ea Compare June 12, 2026 22:35
Base automatically changed from myron/nested-sourced-from-prep to main June 12, 2026 22:57
myronmarston added a commit that referenced this pull request Jun 12, 2026
…om fields. (#1255)

This is the parts of #1252 which are ready to merge.

Co-authored-by: ellisandrews-toast <ellis.andrews@toasttab.com>
@myronmarston
myronmarston force-pushed the nested-sourced-from-script-and-acceptance branch from 4e853ea to b4b5815 Compare June 12, 2026 23:15

@myronmarston myronmarston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good @ellisandrews-toast! Left some feedback.

@myronmarston myronmarston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Left a few more suggestions.

Comment thread config/schema/teams.rb
Comment thread config/schema/teams.rb

@myronmarston myronmarston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to approve with my review above. I view all remaining feedback as fine to defer to a followup.

@ellisandrews-toast

Copy link
Copy Markdown
Collaborator Author

Will open a fresh PR to address remaining feedback after merging this one

@ellisandrews-toast
ellisandrews-toast merged commit c845040 into main Jun 29, 2026
24 checks passed
@ellisandrews-toast
ellisandrews-toast deleted the nested-sourced-from-script-and-acceptance branch June 29, 2026 18:36
jwils added a commit that referenced this pull request Jul 1, 2026
Distilled from the last month of review comments (PRs #1224, #1231, #1247,
#1251, #1252):

Code:
- Polymorphism over `is_a?`/`instance_of?` type checks.
- Core gems stay ignorant of extensions.
- Fix the root cause across a category, not just the reported instance.
- Comment non-obvious "why"; link a tracking issue for known limitations.

Tests:
- Tests must not be satisfiable by a degenerate constant return.
- Make tests self-contained about details that matter.
- Drive behavior through the public API, not internal collaborators.
- Preserve full coverage when relocating tests.
jwils added a commit that referenced this pull request Jul 1, 2026
Distilled from the last month of review comments (PRs #1224, #1231, #1247,
#1251, #1252):

Code:
- Polymorphism over `is_a?`/`instance_of?` type checks.
- Core gems stay ignorant of extensions.
- Fix the root cause across a category, not just the reported instance.
- Comment non-obvious "why"; link a tracking issue for known limitations.

Tests:
- Tests must not be satisfiable by a degenerate constant return.
- Make tests self-contained about details that matter.
- Drive behavior through the public API, not internal collaborators.
- Preserve full coverage when relocating tests.
jwils added a commit that referenced this pull request Jul 2, 2026
Distilled from the last month of review comments (PRs #1224, #1231, #1247,
#1251, #1252):

Code:
- Polymorphism over `is_a?`/`instance_of?` type checks.
- Core gems stay ignorant of extensions.
- Fix the root cause across a category, not just the reported instance.
- Comment non-obvious "why"; link a tracking issue for known limitations.

Tests:
- Tests must not be satisfiable by a degenerate constant return.
- Make tests self-contained about details that matter.
- Drive behavior through the public API, not internal collaborators.
- Preserve full coverage when relocating tests.
anthonycastiglia-toast pushed a commit to anthonycastiglia-toast/elasticgraph that referenced this pull request Jul 10, 2026
…om fields.

This is the parts of block#1252 which are ready to merge.
ellisandrews-toast added a commit that referenced this pull request Jul 15, 2026
Addresses the unresolved (non-blocking) review comments left on
`index_data.painless` in #1252.

Mechanical cleanups only — no behavior change; verified by the existing
nested + top-level multi-source acceptance specs.

- Use `segment.field` map-access shorthand in
`buildNestedElementKeyParts` and `extractNestedElement`
- More optimal null checking / returning in `extractNestedElement`
- Enhance the `findInList` comment (first-match-wins) and reword the
unbounded-growth note to reference #1270

Schema artifacts regenerated (`INDEX_DATA_UPDATE_SCRIPT_ID` updated
accordingly).
ellisandrews-toast added a commit that referenced this pull request Jul 20, 2026
…ling (#1310)

This PR adds a unit test to cover a gap identified in this prior PR, but
deferred:
#1252 (comment)
ellisandrews-toast added a commit that referenced this pull request Jul 23, 2026
Addresses the review threads on #1252 that remained open after it
merged, specifically pertaining to the acceptance tests.

This fills the coverage gaps identified in review — mostly around the
`__nested_sourced_data` buffer's edge cases — and reworks the spec for
readability, so that every detail a test's assertions depend on is
visible in the test body rather than hidden in helper defaults.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants