Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/12856#discussion_r61975859
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/sources/HadoopFsRelationTest.scala
---
@@ -486,7 +488,143 @@ abstract class HadoopFsRelationTest extends QueryTest
with SQLTestUtils with Tes
}
}
- test("Hadoop style globbing") {
+ test("load() - with directory of unpartitioned data in nested subdirs") {
+ withTempPath { file =>
+ val dir = file.getCanonicalPath
+ val subdir = new File(dir, "subdir").getCanonicalPath
+
+ val dataInDir = Seq(1, 2, 3).toDF("value")
+ val dataInSubdir = Seq(4, 5, 6).toDF("value")
+
+ /*
+
+ Directory structure to be generated
+
+ dir
+ |
+ |___ [ files of dataInDir ]
+ |
+ |___ subsubdir
+ |
+ |___ [ files of dataInSubdir ]
+ */
+
+ // Generated dataInSubdir, not data in dir
+ partitionedTestDF1.write
+ .format(dataSourceName)
+ .mode(SaveMode.Overwrite)
+ .save(subdir)
+
+ // Inferring schema should throw error as it should not find any
file to infer
+ val e = intercept[Exception] {
+ sqlContext.read.format(dataSourceName).load(dir)
+ }
+
+ e match {
+ case _: AnalysisException =>
+ assert(e.getMessage.contains("infer"))
+
+ case _: java.util.NoSuchElementException if
e.getMessage.contains("dataSchema") =>
+ // ignore, the source format requires schema to be provided by
user
+
+ case _ =>
+ fail("Unexpected error trying to infer schema from empty dir", e)
+ }
+
+ /** Test whether data is read with the given path matches the
expected answer */
+ def testWithPath(path: String, expectedAnswer: Seq[Row]): Unit = {
+ val df = sqlContext.read
+ .format(dataSourceName)
+ .schema(dataInDir.schema) // avoid schema inference for any
format
+ .load(path)
+ checkAnswer(df, expectedAnswer)
+ }
+
+ // Reading by the path 'file/' *not by 'file/subdir') should give
empty results
+ // as there are no files in 'file' and it should not pick up files
in 'file/subdir'
+ testWithPath(dir, Seq.empty)
+
+ dataInDir.write
+ .format(dataSourceName)
+ .mode(SaveMode.Overwrite)
--- End diff --
Aah... i should fix that and test later whether reading both cases dir and
subdir works as expected
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]