Skip to content

patch_table: positioned index adds (after / first)#161

Merged
orian merged 1 commit into
mainfrom
patch-index-position
Jul 18, 2026
Merged

patch_table: positioned index adds (after / first)#161
orian merged 1 commit into
mainfrom
patch-index-position

Conversation

@orian

@orian orian commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements #160 — the index analogue of #159, unblocking posthog.sharded_events (the last of the 12 order-blocked objects; ~380 columns, per-env minmax_mat_* skip indexes interleaved mid-list).

patch_table "sharded_events" {
  index "minmax_mat_b" {
    expr        = "mat_b"
    type        = "minmax"
    granularity = 1
    after       = "minmax_mat_a"   # or first = true
  }
}

Same semantics as #159's column placement, per the issue:

  • after/first on a patch index add; mutually exclusive; neither keeps the append default.
  • Post-previous-op resolution: drops apply first, so after may name an index added earlier in the same patch and a dropped/unknown target errors. A positioned drop+add redefines an index at a position — drop+add is already the sanctioned redefine path, and a redefine lands where you put it.
  • Placement is transient (cleared on application, diff:"-"): the composed table renders byte-identical to the flat declaration — asserted by test and confirmed with cmp against the built binary.
  • Patch-only: a declared table index carrying placement is a resolve error, including when inherited from an abstract base. Repositioning base indexes stays a full redeclaration.

The column and index paths now share one insertPos helper (column error messages unchanged — #159's tests pass untouched).

Plan doc: docs/plans/2026-07-18-patch-index-position.md; docs updated in the patch_table reference (index bullet + example), README, CLAUDE.md.

Test plan

  • The issue's sharded_events scenario in miniature with byte-parity (Write(base+patch) equals Write(flat)); first + chained after + positioned drop+add redefine in one patch with cleared placement; error paths (both set, unknown target, target dropped in the same patch, declared-index placement, abstract-base inheritance)
  • go test -race ./internal/... ./cmd/... ./test — all green; gofmt -s clean
  • Binary smoke test: composed interleaved index order, cmp byte-identical to the flat declaration

The index analogue of #159's positioned column adds, unblocking the
last object standing from the once-only work: posthog.sharded_events,
whose per-env minmax_mat_* skip indexes interleave mid-list and could
only be appended by a patch.

A patch index add takes after = "<name>" or first = true, with the
same semantics as columns: mutually exclusive, append by default,
resolved against the post-previous-op state (drops apply first, so
after may name an index added earlier in the same patch and a
dropped/unknown target errors, while a positioned drop+add redefines
an index at a position — drop+add is already the sanctioned redefine
path, and a redefine lands where you put it). Placement is transient
and cleared on application, so the composed table renders
byte-identical to the flat declaration; a declared table index carrying
after/first errors at resolve, including via abstract-base
inheritance.

The column and index paths share one insertPos helper; the column error
messages are unchanged.

Closes #160
@orian
orian merged commit 6db99e9 into main Jul 18, 2026
16 checks passed
@orian
orian deleted the patch-index-position branch July 18, 2026 15:51
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