HyukjinKwon commented on a change in pull request #24725: [SPARK-27863][SQL]
Metadata files and temporary files should not be counted as data files
URL: https://github.com/apache/spark/pull/24725#discussion_r288032702
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala
##########
@@ -614,4 +614,39 @@ class StatisticsCollectionSuite extends
StatisticsCollectionTestBase with Shared
}
}
}
+
+ test("Metadata files and temporary files should not be counted as data
files") {
Review comment:
nits:
```diff
@@ -619,7 +619,7 @@ class StatisticsCollectionSuite extends
StatisticsCollectionTestBase with Shared
withTempDir { tempDir =>
val tableName = "t1"
val stagingDirName = ".test-staging-dir"
- val tableLocation = s"${tempDir.getCanonicalPath}/$tableName"
+ val tableLocation = s"${tempDir.toURI}/$tableName"
withSQLConf(
SQLConf.AUTO_SIZE_UPDATE_ENABLED.key -> "true",
"hive.exec.stagingdir" -> stagingDirName) {
@@ -627,21 +627,22 @@ class StatisticsCollectionSuite extends
StatisticsCollectionTestBase with Shared
sql(s"CREATE TABLE $tableName(c1 BIGINT) USING PARQUET LOCATION
'$tableLocation'")
sql(s"INSERT INTO TABLE $tableName VALUES(1)")
- val staging = new File(s"$tableLocation/$stagingDirName")
- val stagingWriter = new PrintWriter(staging)
- stagingWriter.write("12")
- stagingWriter.close()
+ val staging = new File(new URI(s"$tableLocation/$stagingDirName"))
+ Utils.tryWithResource(new PrintWriter(staging)) { stagingWriter =>
+ stagingWriter.write("12")
+ }
+
+ val metadata = new File(new URI(s"$tableLocation/_metadata"))
- val metadata = new File(s"$tableLocation/_metadata")
- val metadataWriter = new PrintWriter(metadata)
- metadataWriter.write("1234")
- metadataWriter.close()
+ Utils.tryWithResource(new PrintWriter(staging)) { metadataWriter
=>
+ metadataWriter.write("1234")
+ }
sql(s"INSERT INTO TABLE $tableName VALUES(1)")
val stagingFileSize = staging.length()
val metadataFileSize = metadata.length()
- val tableLocationSize = getDataSize(new File(tableLocation))
+ val tableLocationSize = getDataSize(new File(new
URI(tableLocation)))
val stats = checkTableStats(tableName, hasSizeInBytes = true,
expectedRowCounts = None)
assert(stats.get.sizeInBytes === tableLocationSize -
stagingFileSize - metadataFileSize)
```
Using URI makes the test working on Windows too. If the test isn't specific
to paths, it's better to stick to using URI.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]