Skip to content

fix: respect path boundary in compareToFileList location prefix matching (#16493) - #17607

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/remove-orphan-files-path-boundary
Open

fix: respect path boundary in compareToFileList location prefix matching (#16493)#17607
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/remove-orphan-files-path-boundary

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #16493

Why

When using compareToFileList(Dataset), the file_list_view is filtered by startsWith(tableLocation). This raw string prefix match incorrectly includes sibling paths that share a prefix with the table location. For example, a table at s3://bucket/table would also match s3://bucket/table-backup/data/file.parquet or s3://bucket/table_old/data/file.parquet, treating files outside the intended directory as in-scope orphan candidates.

Summary

Normalize the location to ensure it ends with a path separator (/) before using startsWith, and also accept an exact match for the location itself. This ensures that only files actually under the table directory (or equal to the location) are treated as in-scope.

How to Test

New test testCompareToFileListDoesNotMatchSiblingPaths verifies that:

  • Files under tableLocation + "-backup/" (sibling prefix) are NOT in scope
  • Files under tableLocation + "_old/" (sibling prefix) are NOT in scope
  • Files under tableLocation + "/data/" are correctly in scope

Type

  • Bug fix
  • Feature
  • Documentation

Checklist

  • Changes are tested
  • Changes follow the project's code style

…ing (apache#16493)

When using compareToFileList(Dataset), the file_list_view is filtered by
startsWith(tableLocation). This raw string prefix match incorrectly
includes sibling paths that share a prefix with the table location, e.g.
s3://bucket/table-backup/... would match a table at s3://bucket/table.

Fix: normalize the location to ensure it ends with path separator before
using startsWith, and also accept exact match for the location itself.

This prevents orphan file cleanup from operating on files outside the
intended table directory when the user provides a file_list_view.

Test: testCompareToFileListDoesNotMatchSiblingPaths verifies that
sibling paths (table-backup/..., table_old/...) are not treated as
in-scope orphan candidates.
@github-actions github-actions Bot added the spark label Aug 11, 2026

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@waterWang Please note that this might already be in progress #16498.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

remove_orphan_files scopes file_list_view with raw string prefix matching

2 participants