Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ class TextSuite extends QueryTest with SharedSQLContext {
}
}

test("Write and read back empty data") {
withTempPath { path =>
val df = spark.read.format("text").load(testFile)
val emptyDf = df.limit(0)
emptyDf.write
.format("text")
.save(path.getCanonicalPath)

val copyEmptyDf = spark.read
.format("text")
.load(path.getCanonicalPath)

checkAnswer(emptyDf, copyEmptyDf)
}
}

private def testFile: String = {
Thread.currentThread().getContextClassLoader.getResource("text-suite.txt").toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,19 @@ class JsonHadoopFsRelationSuite extends HadoopFsRelationTest {
)
}
}

test("Write and read back empty data") {
withTempPath { path =>
val emptyDf = spark.range(10).limit(0).toDF()
emptyDf.write
.format(dataSourceName)
.save(path.getCanonicalPath)

val copyEmptyDf = spark.read
.format(dataSourceName)
.load(path.getCanonicalPath)

assert(copyEmptyDf.count() === 0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,19 @@ class ParquetHadoopFsRelationSuite extends HadoopFsRelationTest {
}
}
}

test("Write and read back empty data") {
withTempPath { path =>
val emptyDf = spark.range(10).limit(0).toDF()
emptyDf.write
.format(dataSourceName)
.save(path.getCanonicalPath)

val copyEmptyDf = spark.read
.format(dataSourceName)
.load(path.getCanonicalPath)

checkAnswer(emptyDf, copyEmptyDf)
}
}
}