locate: add -group-by option#441
Merged
Merged
Conversation
2 tasks
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>
eae110f to
94696c8
Compare
ericfaurot
approved these changes
May 28, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
-group-byoption toLocateOptions. 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 1keeps 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'spruneis needed so the parsed flag isn't dropped bymergePolicyOptions(PlakarKorp/plakar#2162).Commits
locate: add a -group-by option— the core changelocate: extend filters and -group-by with dataset and data classes— picks up theDataset/DataClassesfields added in 4cf3d58; adds-datasetand-data-classflagsTest 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,-latestinteraction, empty input, unknown key fallback; the dataset/data-class commit adds flag parsing, filtering, fan-out grouping and integration testsgo test ./...greenlsandprune -apply