Skip to content

Commit 325b9c4

Browse files
authored
Merge pull request #8 from dongjoon-hyun/SPARK-25425
Add a test case for write path. Thank you very much, @dongjoon-hyun
2 parents eba46d9 + d35d01b commit 325b9c4

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2Suite.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.spark.sql.sources.v2
1919

20+
import java.io.File
21+
2022
import test.org.apache.spark.sql.sources.v2._
2123

2224
import org.apache.spark.SparkException
@@ -318,7 +320,7 @@ class DataSourceV2Suite extends QueryTest with SharedSQLContext {
318320
checkCanonicalizedOutput(df.select('i), 2, 1)
319321
}
320322

321-
test("SPARK-25425: extra options override sessions options") {
323+
test("SPARK-25425: extra options should override sessions options during reading") {
322324
val prefix = "spark.datasource.userDefinedDataSource."
323325
val optionName = "optionA"
324326
withSQLConf(prefix + optionName -> "true") {
@@ -332,6 +334,23 @@ class DataSourceV2Suite extends QueryTest with SharedSQLContext {
332334
assert(options.get.get(optionName) == Some("false"))
333335
}
334336
}
337+
338+
test("SPARK-25425: extra options should override sessions options during writing") {
339+
withTempPath { path =>
340+
val sessionPath = path.getCanonicalPath
341+
withSQLConf("spark.datasource.simpleWritableDataSource.path" -> sessionPath) {
342+
withTempPath { file =>
343+
val optionPath = file.getCanonicalPath
344+
val format = classOf[SimpleWritableDataSource].getName
345+
346+
val df = Seq((1L, 2L)).toDF("i", "j")
347+
df.write.format(format).option("path", optionPath).save()
348+
assert(!new File(sessionPath).exists)
349+
checkAnswer(spark.read.format(format).option("path", optionPath).load(), df)
350+
}
351+
}
352+
}
353+
}
335354
}
336355

337356

sql/core/src/test/scala/org/apache/spark/sql/sources/v2/SimpleWritableDataSource.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ import org.apache.spark.util.SerializableConfiguration
3939
* Each job moves files from `target/_temporary/queryId/` to `target`.
4040
*/
4141
class SimpleWritableDataSource extends DataSourceV2
42-
with BatchReadSupportProvider with BatchWriteSupportProvider {
42+
with BatchReadSupportProvider
43+
with BatchWriteSupportProvider
44+
with SessionConfigSupport {
4345

4446
private val schema = new StructType().add("i", "long").add("j", "long")
4547

48+
override def keyPrefix: String = "simpleWritableDataSource"
49+
4650
class ReadSupport(path: String, conf: Configuration) extends SimpleReadSupport {
4751

4852
override def fullSchema(): StructType = schema

0 commit comments

Comments
 (0)