Skip to content

feat(file): add newest_by_stem to read only the newest of same-name files - #144

Open
Ankur Gupta (ankur-pattern) wants to merge 2 commits into
mainfrom
DATA-12008-file-newest-by-stem
Open

Ankur Gupta (ankur-pattern) wants to merge 2 commits into
mainfrom
DATA-12008-file-newest-by-stem

Conversation

@ankur-pattern

@ankur-pattern Ankur Gupta (ankur-pattern) commented Dec 2, 2026 •

Copy link
Copy Markdown

Summary

  • Adds newest_by_stem to the file task's read mode. When it is set, of the matched files in the same directory whose names differ only by extension (for example report.xlsx and report.tsv), only the most recently modified one is read.
  • "Most recently modified" is the S3 object's LastModified, or the file's modification time for local paths.
  • Off by default, so existing reads are unchanged.

Test plan

  • go build ./..., go vet -copylocks=false ./..., go test -race ./...
  • Local glob over an older report.xlsx, a newer report.tsv and other.xlsx: with newest_by_stem: true only report.tsv and other.xlsx are read, and without it all three are
  • test/pipelines/file_read_failure.yaml still fails as on main
  • An S3 prefix holding both report.xlsx and report.tsv reads only the newer object

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues violate retained file ordering and make disabled newest-by-stem reads abort on unnecessary stat failures, potentially dropping readable files without failing the pipeline.

2 open issues
What changed in this PR

Adds opt-in newest_by_stem selection to file sources so pipelines can choose the latest report across extensions before downstream conversion.

Changes:

  • Selects one file per directory and stem using local or S3 modification times.
  • Adds deterministic tie-breaking and logs skipped files.
  • Documents the option and adds grouping and local-read tests.
File Description
internal/​pkg/​pipeline/​task/​file/​s3.go Includes S3 modification times in listed sources.
internal/​pkg/​pipeline/​task/​file/​README.md Documents selection rules and configuration.
internal/​pkg/​pipeline/​task/​file/​local.go Collects local modification times.
internal/​pkg/​pipeline/​task/​file/​file.go Adds configuration, selection logic, and skip logging.
internal/​pkg/​pipeline/​task/​file/​file_test.go Tests grouping rules and enabled/disabled local reads.

Review effort: Balanced

Comment thread internal/pkg/pipeline/task/file/file.go Resolved
@ankur-pattern

Copy link
Copy Markdown
Author

/argus review

@ankur-pattern Ankur Gupta (ankur-pattern) changed the title feat(file): read only the newest of same-name files with newest_by_stem feat(file): add newest_by_stem to read only the newest of same-name files Dec 2, 2026
@ankur-pattern

Copy link
Copy Markdown
Author

/argus review

Comment thread internal/pkg/pipeline/task/file/file.go Resolved
Comment thread internal/pkg/pipeline/task/file/file.go Resolved

@argus-pattern argus-pattern Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Argus review of aed67d2: checked the newest_by_stem grouping logic, the reader.parse signature change (both implementations updated; no other callers), S3 LastModified / local mtime collection, and the README entry. Inline comments cover the dotfile grouping edge case, silent skips, and the unconditional local os.Stat.

No tests for newest_by_stem
Severity: Medium

The PR adds a selection rule that drops input files, but the head commit adds no tests (the file package has no _test.go), and the S3 path is still unchecked in the test plan. newestByStem is a pure function over []source, so it can be tested without S3 or the filesystem.

Fix: Add a table-driven file_test.go covering: same stem with different extensions (newer wins, either listing order); same stem in different directories (both kept); different stems (both kept); equal modification times (first listed kept, which matters for S3's one-second LastModified precision); multi-dot names like a.tar.gz vs a.zip; and leading-dot names. Add one readFile test over a temp dir with newest_by_stem on and off.

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.

3 participants