Skip to content

Commit 261b9ad

Browse files
committed
add test in DataFrameReaderWriterSuite
1 parent 617ab8f commit 261b9ad

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileIndexSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class FileIndexSuite extends SharedSparkSession {
360360
stringToFile(file, "text")
361361
val path = new Path(dir.getCanonicalPath)
362362
val wrongBasePath = new File(dir, "unknown")
363+
// basePath must be a directory
363364
wrongBasePath.mkdir()
364365
val parameters = Map("basePath" -> wrongBasePath.getCanonicalPath)
365366
val fileIndex = new InMemoryFileIndex(spark, Seq(path), parameters, None)

sql/core/src/test/scala/org/apache/spark/sql/test/DataFrameReaderWriterSuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSparkSession with
234234
assert(DataSourceUtils.decodePartitioningColumns(partColumns) === Seq("col1", "col2"))
235235
}
236236

237+
test ("SPARK-29537: throw exception when user defined a wrong base path") {
238+
withTempPath { p =>
239+
val path = new Path(p.toURI).toString
240+
Seq((1, 1), (2, 2)).toDF("c1", "c2")
241+
.write.partitionBy("c1").mode(SaveMode.Overwrite).parquet(path)
242+
val wrongBasePath = new File(p, "unknown")
243+
// basePath must be a directory
244+
wrongBasePath.mkdir()
245+
val msg = intercept[IllegalArgumentException] {
246+
spark.read.option("basePath", wrongBasePath.getCanonicalPath).parquet(path)
247+
}.getMessage
248+
assert(msg === s"Wrong basePath ${wrongBasePath.getCanonicalPath} for the root path: $path")
249+
}
250+
}
251+
237252
test("save mode") {
238253
spark.range(10).write
239254
.format("org.apache.spark.sql.test")

0 commit comments

Comments
 (0)