Skip to content

Commit 416da98

Browse files
committed
address comments
1 parent f555949 commit 416da98

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,24 @@ class SimpleWritableDataSource extends DataSourceV2 with ReadSupport with WriteS
125125
val internal = options.get("internal").isPresent
126126
val conf = SparkContext.getActive.get.hadoopConfiguration
127127
val fs = path.getFileSystem(conf)
128-
if (fs.exists(path)) {
129-
if (mode == SaveMode.ErrorIfExists) {
128+
129+
if (mode == SaveMode.ErrorIfExists) {
130+
if (fs.exists(path)) {
130131
throw new RuntimeException("data already exists.")
131132
}
132-
133-
if (mode == SaveMode.Ignore) {
134-
Optional.empty()
135-
} else if (mode == SaveMode.Overwrite) {
133+
}
134+
if (mode == SaveMode.Ignore) {
135+
if (fs.exists(path)) {
136+
return Optional.empty()
137+
}
138+
}
139+
if (mode == SaveMode.Overwrite) {
140+
if (fs.exists(path)) {
136141
fs.delete(path, true)
137-
Optional.of(createWriter(path, conf, internal))
138-
} else {
139-
assert(mode == SaveMode.Append)
140-
Optional.of(createWriter(path, conf, internal))
141142
}
142-
} else {
143-
Optional.of(createWriter(path, conf, internal))
144143
}
144+
145+
Optional.of(createWriter(path, conf, internal))
145146
}
146147

147148
private def createWriter(

0 commit comments

Comments
 (0)