Skip to content

locate: add -group-by option#441

Merged
poolpOrg merged 2 commits into
mainfrom
feature/locate-group-by
May 28, 2026
Merged

locate: add -group-by option#441
poolpOrg merged 2 commits into
mainfrom
feature/locate-group-by

Conversation

@poolpOrg
Copy link
Copy Markdown
Contributor

@poolpOrg poolpOrg commented May 27, 2026

Summary

Adds a -group-by option to LocateOptions. Filtering runs first, then results are partitioned by the chosen key, then retention rules apply independently within each group.

Useful for retention policies like "keep the newest snapshot per name" — without -group-by, -days 1 -per-day 1 keeps a single snapshot across the whole result; with -group-by name, it keeps the newest of each name.

Supported keys: name, category, environment, perimeter, job, dataset, data-class, tag, origin, type, root. Multi-valued keys (tag/origin/type/root/data-class) fan out: an item participates in every group it belongs to, and keep wins over delete when flattening.

Wired into all callers transparently via opts.Match. A small companion change in plakar's prune is needed so the parsed flag isn't dropped by mergePolicyOptions (PlakarKorp/plakar#2162).

Commits

  • locate: add a -group-by option — the core change
  • locate: extend filters and -group-by with dataset and data classes — picks up the Dataset/DataClasses fields added in 4cf3d58; adds -dataset and -data-class flags

Test plan

  • go test ./locate/ — covers no-op without periods, filter-then-group order, per-group retention vs flat retention, each single-valued key, fanout across multi-valued keys, keep-wins-over-delete on fanout, missing-field bucketing, -latest interaction, empty input, unknown key fallback; the dataset/data-class commit adds flag parsing, filtering, fan-out grouping and integration tests
  • go test ./... green
  • Exercised end-to-end against a real repo with ls and prune -apply

@poolpOrg poolpOrg marked this pull request as ready for review May 27, 2026 21:22
@PlakarKorp PlakarKorp deleted a comment from codecov Bot May 27, 2026
poolpOrg and others added 2 commits May 28, 2026 01:17
Lets retention rules apply per group instead of across the whole result
set. -group-by name with -days 1 -per-day 1 keeps the newest snapshot
per name, not just the newest overall.

Filters run first, then grouping, then per-group retention. With no
periods set the option is a no-op.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The snapshot header gained Dataset and DataClasses (4cf3d58) but those
fields weren't reachable from locate yet.

Adds -dataset and -data-class flags, dataset and data-class group-by
keys, and wires both into buildPolicyItems so ls, prune and locate pick
them up. -data-class follows the same any-match semantics as -origin
and -type; -group-by data-class fans out across all classes an item
carries.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@poolpOrg poolpOrg force-pushed the feature/locate-group-by branch from eae110f to 94696c8 Compare May 27, 2026 23:22
@poolpOrg poolpOrg merged commit 7113533 into main May 28, 2026
7 checks passed
@poolpOrg poolpOrg deleted the feature/locate-group-by branch May 28, 2026 20:45
poolpOrg added a commit to PlakarKorp/plakar that referenced this pull request May 29, 2026
mergePolicyOptions overwrites Filters but used to drop GroupBy on the
floor, so -group-by parsed from the command line never reached Match.

Document -group-by in plakar-query(7).

Requires the GroupBy field on locate.LocateOptions
(PlakarKorp/kloset#441).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
poolpOrg added a commit to PlakarKorp/plakar that referenced this pull request May 29, 2026
mergePolicyOptions overwrites Filters but used to drop GroupBy on the
floor, so -group-by parsed from the command line never reached Match.

Document -group-by in plakar-query(7).

Requires the GroupBy field on locate.LocateOptions
(PlakarKorp/kloset#441).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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