-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-34326][CORE][SQL] Fix UTs added in SPARK-31793 depending on the length of temp path #31449
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 1 commit
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package org.apache.spark.sql.execution | |
| import java.io.File | ||
|
|
||
| import scala.collection.mutable | ||
| import scala.util.Random | ||
|
|
||
| import org.apache.hadoop.fs.Path | ||
|
|
||
|
|
@@ -122,24 +123,45 @@ class DataSourceScanExecRedactionSuite extends DataSourceScanRedactionTest { | |
| test("SPARK-31793: FileSourceScanExec metadata should contain limited file paths") { | ||
| withTempPath { path => | ||
| val dir = path.getCanonicalPath | ||
|
|
||
| // create a sub-directory with long name so that each root path will always exceed the limit | ||
| // this is to ensure we always test the case for the path truncation | ||
| // 110 = limit 100 + margin 10 to clearly avoid edge case | ||
| val dataDir = if (dir.length >= 110) { | ||
|
||
| path | ||
| } else { | ||
| val dataDirName = Random.alphanumeric.take(110 - dir.length).toList.mkString | ||
| val f = new File(path, dataDirName) | ||
| f.mkdir() | ||
| f | ||
| } | ||
|
|
||
| val partitionCol = "partitionCol" | ||
| spark.range(10) | ||
| .select("id", "id") | ||
| .toDF("value", partitionCol) | ||
| .write | ||
| .partitionBy(partitionCol) | ||
| .orc(dir) | ||
| val paths = (0 to 9).map(i => new File(dir, s"$partitionCol=$i").getCanonicalPath) | ||
| .orc(dataDir.getCanonicalPath) | ||
| val paths = (0 to 9).map(i => new File(dataDir, s"$partitionCol=$i").getCanonicalPath) | ||
| val plan = spark.read.orc(paths: _*).queryExecution.executedPlan | ||
| val location = plan collectFirst { | ||
| case f: FileSourceScanExec => f.metadata("Location") | ||
| } | ||
| assert(location.isDefined) | ||
| // The location metadata should at least contain one path | ||
| assert(location.get.contains(paths.head)) | ||
| // If the temp path length is larger than 100, the metadata length should not exceed | ||
| // twice of the length; otherwise, the metadata length should be controlled within 200. | ||
| assert(location.get.length < Math.max(paths.head.length, 100) * 2) | ||
|
|
||
| // The location metadata should have bracket wrapping paths | ||
| assert(location.get.indexOf('[') > -1) | ||
| assert(location.get.indexOf(']') > -1) | ||
|
|
||
| // extract paths in location metadata (removing classname, brackets, separators) | ||
| val pathsInLocation = location.get.substring( | ||
| location.get.indexOf('[') + 1, location.get.indexOf(']')).split(", ").toSeq | ||
|
|
||
| // the only one path should be available | ||
| assert(pathsInLocation.size == 1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
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 just ensure we test on path truncation; other cases should be tested against UtilsSuite.