FEAT: Add CATERPILLAR_FILE_PATH_WRITE context key (DATA-8693)#77
Open
snehalahire-pattern wants to merge 4 commits into
Open
FEAT: Add CATERPILLAR_FILE_PATH_WRITE context key (DATA-8693)#77snehalahire-pattern wants to merge 4 commits into
snehalahire-pattern wants to merge 4 commits into
Conversation
Expose the sanitized full source path as a record context value on the file task's read mode, alongside the existing CATERPILLAR_FILE_NAME_WRITE (base name only). Path segments are slugified individually with "/" preserved between them, so the directory hierarchy survives and can be used in destination paths to avoid same-name collisions when reading nested folders with a recursive glob (e.g. reportType=X/**/**.tsv). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| @@ -146,6 +146,7 @@ func (f *file) readFile(output chan<- *record.Record) error { | |||
| // Create a default record with context | |||
| rc := &record.Record{Context: ctx} | |||
| rc.SetContextValue(string(task.CtxKeyFileNameWrite), textutil.SlugifyFileName(filepath.Base(path))) | |||
Contributor
There was a problem hiding this comment.
Can we create a single variable for the value generated by textutil.SlugifyFileName and reuse it wherever needed? This would help avoid code duplication and improve maintainability.
Contributor
Author
There was a problem hiding this comment.
Mahesh Kamble (@ma-gk) SlugifyFileName is used only once, the other one is SlugifyFilePath.
Do you mean the same or something else?
- Extract URL scheme stripping in SlugifyFilePath into a stripURLScheme helper. - Hoist the slugified file name into a local variable in the file task. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| In read mode, two values are stored in each record's context: | ||
|
|
||
| - `CATERPILLAR_FILE_NAME_WRITE` — the sanitized base filename. The stem is lowercased with non-alphanumeric characters replaced by underscores, while the extension is preserved and lowercased (e.g. `"Report 1.CSV"` → `"report_1.csv"`). | ||
| - `CATERPILLAR_FILE_PATH_WRITE` — the sanitized full source path with directory hierarchy preserved. Each segment is slugified the same way; the final segment keeps its extension; URL schemes such as `s3://bucket/` are stripped (e.g. `s3://my-bucket/ReportType=A/Folder 1/data.CSV` → `reporttype_a/folder_1/data.csv`). Reference it in the destination of a downstream write task to avoid collisions when reading nested directories with a recursive glob. |
Contributor
There was a problem hiding this comment.
Do we have any use case/example where we would be leveraging this sluggified file path?
Mayuresh Pawar (Mayureshpawar29)
approved these changes
Jun 24, 2026
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
CATERPILLAR_FILE_PATH_WRITEpopulated by the file task's read mode, alongside the existingCATERPILLAR_FILE_NAME_WRITE(which is unchanged for backward compatibility).textutil.SlugifyFilePathhelper slugifies each path segment individually so the/hierarchy is preserved; URL schemes likes3://bucket/are stripped, the final segment keeps its extension. e.g.s3://my-bucket/ReportType=A/Folder 1/data.CSV→reporttype_a/folder_1/data.csv..../ds={{ ds }}/{{ context "CATERPILLAR_FILE_PATH_WRITE" }}), avoiding same-name collisions when reading nested directories with a recursive glob (e.g.reportType=X/**/**.tsv).ClickUp
DATA-8693
Note on overlapping work
A separate branch
feat/file-path-write-context(commitac18420) takes a different approach to the same ticket: it slugifies the full path into a single flat segment (collapsing/to_) and also wires the new key into the archive/sftp tasks. This PR preserves the directory hierarchy literally, per the ticket's "Path information preserves folder hierarchy" criterion, and is scoped to the file task. Reviewers should pick one approach before merging.Test plan
go build ./...clean (verified locally)go test ./...green (verified locally)reportType=X/**/**.tsvand writing to.../{{ context "CATERPILLAR_FILE_PATH_WRITE" }}; confirm files from different subdirectories no longer overwrite each other in the destination.CATERPILLAR_FILE_NAME_WRITEcontinue to behave identically.🤖 Generated with Claude Code