Skip to content

M6d: tuple-stream group-by — the reduce half of joins#21

Merged
flearc merged 2 commits into
mainfrom
feature/m6d-group-reduce
Jun 25, 2026
Merged

M6d: tuple-stream group-by — the reduce half of joins#21
flearc merged 2 commits into
mainfrom
feature/m6d-group-reduce

Conversation

@flearc

@flearc flearc commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Summary

Ports JSONata v2.2.1's reduceTupleStream so the {…} group-by operator propagates tuple-stream bindings ($e/$c/$i from @$v/#$v) into its key/value expressions — the "reduce" half of map-reduce joins (M6c delivered the "map" half).

  • Evaluator (c3e3c84): two helpers — tuple_append (jsonata fn.append) and reduce_tuple_stream (merge a group's tuples, appending each binding so $c becomes every contact in the group; a 1-member group keeps the scalar). eval_group_step gains a tuple_mode: the key is evaluated with a per-tuple frame; the value is evaluated against the merged tuple's @ (group context) under a frame binding the merged members (so both $join($c.Phone.number) and bare Phone.number value shapes work). The eval_path_tuple group branch passes tuples through instead of collapsing to @-values. The non-tuple group-by path is byte-identical.
  • Baseline (1930760): official-suite regen, zero regressions.

Results

  • Official suite 1237 → 1246 (+9); joins group 27 → 36/43 (employee-map-reduce 1–6,9,10 + the index group-by case).
  • 488 unit tests green; zero-regression guard green (group-by/transform/sorting byte-identical — eval_group_step's non-tuple path is unchanged).
  • Adversarial review vs genuine jsonata-js v2.2.1: no in-scope divergences. Verified multi/single-member reduce, context-vs-binding value shapes, value-side ^($) sort, index group-by, D1009/T1003. On the empty-tuple-stream edge we return {} while jsonata-js throws an uncaught TypeError (upstream bug) — we keep the graceful result.

Deferred (the remaining joins gaps)

  • Cases 7,8 — sort-on-a-focus-step (Employee@$e^($e.Surname)…): a separate sort-tuple-stream bug (we return null, no crash).
  • M6c reorder cases — filter/sort before # (ordered-stages).

Test plan

  • busted spec/ — 488/0
  • busted spec/jsonata_suite_spec.lua — zero-regression guard green
  • bash scripts/run-suite.sh — 1246/1682, joins 36/43
  • Adversarial oracle fidelity review (jsonata@2.2.1)

🤖 Generated with Claude Code

flearc and others added 2 commits June 25, 2026 02:16
…n {…}

eval_group_step gains a tuple_mode: the key sees a per-tuple frame and the
grouped data holds tuples; the value evaluates against a reduced/merged tuple
(its @ is the group context, its bindings the appended members). The group
branch in eval_path_tuple passes tuples through instead of collapsing to
@-values. Non-tuple group-by is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…o regressions

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@flearc flearc merged commit 2b93499 into main Jun 25, 2026
1 check passed
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.

1 participant