Skip to content

Commit 757626f

Browse files
committed
address comments
1 parent 74dd5c7 commit 757626f

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,16 +2910,17 @@ private[spark] object Utils extends Logging {
29102910
* exceeds `stopAppendingThreshold`, stop appending paths for saving memory.
29112911
*/
29122912
def buildLocationMetadata(paths: Seq[Path], stopAppendingThreshold: Int): String = {
2913-
var metadata = "["
2913+
val metadata = new StringBuilder("[")
29142914
var index: Int = 0
29152915
while (index < paths.length && metadata.length <= stopAppendingThreshold) {
29162916
if (index > 0) {
2917-
metadata += ", "
2917+
metadata.append(", ")
29182918
}
2919-
metadata += paths(index).toString
2919+
metadata.append(paths(index).toString)
29202920
index += 1
29212921
}
2922-
metadata + "]"
2922+
metadata.append("]")
2923+
metadata.toString
29232924
}
29242925
}
29252926

sql/core/src/test/scala/org/apache/spark/sql/execution/DataSourceScanExecRedactionSuite.scala

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,17 @@ class DataSourceScanExecRedactionSuite extends DataSourceScanRedactionTest {
127127
.write
128128
.partitionBy(partitionCol)
129129
.orc(dir)
130-
val paths = (0 to 9).map(i => dir + "/" + partitionCol + "=" + i)
131-
val plan = spark
132-
.read
133-
.orc(paths: _*)
134-
.queryExecution
135-
.executedPlan
130+
val paths = (0 to 9).map(i => s"$dir/$partitionCol=$i")
131+
val plan = spark.read.orc(paths: _*).queryExecution.executedPlan
136132
val location = plan collectFirst {
137133
case f: FileSourceScanExec => f.metadata("Location")
138134
}
139135
assert(location.isDefined)
140-
var found = false
141-
for (index <- 1 to 10) {
142-
val tempLocation = paths.slice(0, index).mkString("[", ", ", "]")
143-
if (tempLocation.length >= 100 && !found) {
144-
found = true
145-
for (tempIndex <- 0 until index) {
146-
assert(location.get.contains(paths(tempIndex)))
147-
}
148-
}
149-
}
136+
// The location metadata should at least contain one path
137+
assert(location.get.contains(paths.head))
138+
// If the temp path length is larger than 100, the metadata length should not exceed
139+
// twice of the length; otherwise, the metadata length should be controlled within 200.
140+
assert(location.get.length < Math.max(paths.head.length, 100) * 2)
150141
}
151142
}
152143
}

0 commit comments

Comments
 (0)