Core: Treat path prefixes as literals in RewriteTablePathUtil.replacePaths - #17521
Open
uros-b wants to merge 1 commit into
Open
Core: Treat path prefixes as literals in RewriteTablePathUtil.replacePaths#17521uros-b wants to merge 1 commit into
uros-b wants to merge 1 commit into
Conversation
5 tasks
Member
Author
|
cc @szehon-ho |
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.
RewriteTablePathUtil.replacePathsrewrote the table location withString.replaceFirst(sourcePrefix, targetPrefix), which interprets the user-suppliedsourcePrefixas a regular expression andtargetPrefixas a replacement string.Both are file paths, so this misbehaves whenever a path contains regex metacharacters:
sourcePrefix = s3://bucket/warehouse.db/tablealso matchess3://bucket/warehouseXdb/table, rewriting a location that is not under the prefix.sourcePrefixwith a trailing separator (e.g.s3://bucket/warehouse/table/) does notmatch at all, so the location is silently left pointing at the source while every
other path is rewritten to the target.
targetPrefixcontaining$fails withIndexOutOfBoundsException: No group 1, and apath containing an unbalanced
[fails withPatternSyntaxException.Every other path rewrite in this class already goes through
newPath()->relativize(),which compares prefixes literally (
startsWith+substring), normalizes trailingseparators, and raises a clear
IllegalArgumentExceptionwhen a path is not under thesource prefix. In
RewriteTablePathSparkAction#rewriteVersionFilethe immediatelypreceding
stagingPath(...)call already applies that literal check, so this change makesthe location rewrite consistent with the validation already performed one line earlier.
Both prefixes are user-supplied through the public
RewriteTablePath.rewriteLocationPrefix(sourcePrefix, targetPrefix)API.Tested with
TestRewriteTablePathUtil(core) andTestRewriteTablePathsActionon Spark3.5, 4.0 and 4.1.
Note: #14355 makes the same one-line change as a side effect of adding multiple
source/destination prefixes. This is the minimal standalone fix plus regression tests for
the metacharacter and trailing-separator cases, so it can land independently; whichever
merges first, the other should rebase cleanly on this method.