Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12856#discussion_r61976246
  
    --- 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)
    +        .save(dir)
    +
    +      // Should give only rows from partitionedTestDF2
    +      testWithPath(dir, dataInDir.collect())
    +    }
    +  }
    +
    +  test("Hadoop style globbing - unpartitioned data") {
    +    withTempPath { file =>
    +
    +      val dir = file.getCanonicalPath
    +      val subdir = new File(dir, "subdir").getCanonicalPath
    +      val subsubdir = new File(subdir, "subsubdir").getCanonicalPath
    +      val anotherSubsubdir =
    +        new File(new File(dir, "another-subdir"), 
"another-subsubdir").getCanonicalPath
    +
    +      val dataInSubdir = Seq(1, 2, 3).toDF("value")
    +      val dataInSubsubdir = Seq(4, 5, 6).toDF("value")
    +      val dataInAnotherSubsubdir = Seq(7, 8, 9).toDF("value")
    +
    +      dataInSubdir.write
    +        .format (dataSourceName)
    +        .mode (SaveMode.Overwrite)
    +        .save (subdir)
    +
    +      dataInSubsubdir.write
    +        .format (dataSourceName)
    +        .mode (SaveMode.Overwrite)
    +        .save (subsubdir)
    +
    +      dataInAnotherSubsubdir.write
    +        .format (dataSourceName)
    +        .mode (SaveMode.Overwrite)
    +        .save (anotherSubsubdir)
    --- End diff --
    
    Maybe manually check if we are generating the desired dir structure? (I 
think we will. But, it is good to double check.)


---
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]

Reply via email to