-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29537][SQL] throw exception when user defined a wrong base path #26195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
746a97e
f7ecb15
358bc0e
617ab8f
261b9ad
66f0bd3
e270fea
e889cda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,7 +221,16 @@ abstract class PartitioningAwareFileIndex( | |
| if (!fs.isDirectory(userDefinedBasePath)) { | ||
| throw new IllegalArgumentException(s"Option '$BASE_PATH_PARAM' must be a directory") | ||
| } | ||
| Set(fs.makeQualified(userDefinedBasePath)) | ||
| def qualifiedPath(path: Path): String = fs.makeQualified(path).toString | ||
|
|
||
| val qualifiedBasePath = qualifiedPath(userDefinedBasePath) | ||
| rootPaths | ||
| .find(p => !qualifiedPath(p).startsWith(qualifiedBasePath)) | ||
| .foreach { rp => | ||
| throw new IllegalArgumentException( | ||
| s"Wrong basePath $userDefinedBasePath for the root path: $rp") | ||
| } | ||
| Set(new Path(qualifiedBasePath)) | ||
|
||
|
|
||
| case None => | ||
| rootPaths.map { path => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -352,6 +352,26 @@ class FileIndexSuite extends SharedSparkSession { | |
| "driver side must not be negative")) | ||
| } | ||
|
|
||
| test ("SPARK-29537: throw exception when user defined a wrong base path") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's also add an end-to-end test with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added 261b9ad |
||
| withTempDir { dir => | ||
| val partitionDirectory = new File(dir, "a=foo") | ||
| partitionDirectory.mkdir() | ||
| val file = new File(partitionDirectory, "text.txt") | ||
| stringToFile(file, "text") | ||
| val path = new Path(dir.getCanonicalPath) | ||
| val wrongBasePath = new File(dir, "unknown") | ||
| // basePath must be a directory | ||
| wrongBasePath.mkdir() | ||
| val parameters = Map("basePath" -> wrongBasePath.getCanonicalPath) | ||
| val fileIndex = new InMemoryFileIndex(spark, Seq(path), parameters, None) | ||
| val msg = intercept[IllegalArgumentException] { | ||
| // trigger inferPartitioning() | ||
| fileIndex.partitionSpec() | ||
| }.getMessage | ||
| assert(msg === s"Wrong basePath ${wrongBasePath.getCanonicalPath} for the root path: $path") | ||
| } | ||
| } | ||
|
|
||
| test("refresh for InMemoryFileIndex with FileStatusCache") { | ||
| withTempDir { dir => | ||
| val fileStatusCache = FileStatusCache.getOrCreate(spark) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call
toStringhere, to avoid callingtoStringlater many timesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can even call
toStringinqualifiedPathand remove the needs to call.toStringaltogether.