@@ -489,9 +489,8 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils with Tes
489489 }
490490
491491 test(" load() - with directory of unpartitioned data in nested subdirs" ) {
492- withTempPath { file =>
493- val dir = file.getCanonicalPath
494- val subdir = new File (dir, " subdir" ).getCanonicalPath
492+ withTempPath { dir =>
493+ val subdir = new File (dir, " subdir" )
495494
496495 val dataInDir = Seq (1 , 2 , 3 ).toDF(" value" )
497496 val dataInSubdir = Seq (4 , 5 , 6 ).toDF(" value" )
@@ -503,21 +502,24 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils with Tes
503502 dir
504503 |
505504 |___ [ files of dataInDir ]
506- |
507- |___ subsubdir
508- |
509- |___ [ files of dataInSubdir ]
505+ |
506+ |___ subsubdir
507+ |
508+ |___ [ files of dataInSubdir ]
510509 */
511510
512511 // Generated dataInSubdir, not data in dir
513- partitionedTestDF1 .write
512+ dataInSubdir .write
514513 .format(dataSourceName)
515514 .mode(SaveMode .Overwrite )
516- .save(subdir)
515+ .save(subdir.getCanonicalPath)
516+
517+ require(subdir.exists)
518+ require(subdir.listFiles().exists(! _.isDirectory))
517519
518520 // Inferring schema should throw error as it should not find any file to infer
519521 val e = intercept[Exception ] {
520- sqlContext.read.format(dataSourceName).load(dir)
522+ sqlContext.read.format(dataSourceName).load(dir.getCanonicalPath )
521523 }
522524
523525 e match {
@@ -532,24 +534,25 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils with Tes
532534 }
533535
534536 /** Test whether data is read with the given path matches the expected answer */
535- def testWithPath (path : String , expectedAnswer : Seq [Row ]): Unit = {
537+ def testWithPath (path : File , expectedAnswer : Seq [Row ]): Unit = {
536538 val df = sqlContext.read
537539 .format(dataSourceName)
538540 .schema(dataInDir.schema) // avoid schema inference for any format
539- .load(path)
541+ .load(path.getCanonicalPath )
540542 checkAnswer(df, expectedAnswer)
541543 }
542544
543- // Reading by the path 'file /' *not by 'file/subdir') should give empty results
544- // as there are no files in 'file' and it should not pick up files in 'file /subdir'
545+ // Verify that reading by path 'dir /' gives empty results as there are no files in 'file'
546+ // and it should not pick up files in 'dir /subdir'
545547 testWithPath(dir, Seq .empty)
546548
549+ // Verify that if there is data in dir, then reading by path 'dir/' reads only dataInDir
547550 dataInDir.write
548551 .format(dataSourceName)
549- .mode(SaveMode .Overwrite )
550- .save(dir)
551-
552- // Should give only rows from partitionedTestDF2
552+ .mode(SaveMode .Ignore )
553+ .save(dir.getCanonicalPath )
554+ require(dir.listFiles().exists( ! _.isDirectory))
555+ require(subdir.listFiles().exists( ! _.isDirectory))
553556 testWithPath(dir, dataInDir.collect())
554557 }
555558 }
@@ -558,10 +561,10 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils with Tes
558561 withTempPath { file =>
559562
560563 val dir = file.getCanonicalPath
561- val subdir = new File (dir, " subdir" ).getCanonicalPath
562- val subsubdir = new File (subdir, " subsubdir" ).getCanonicalPath
564+ val subdir = new File (dir, " subdir" )
565+ val subsubdir = new File (subdir, " subsubdir" )
563566 val anotherSubsubdir =
564- new File (new File (dir, " another-subdir" ), " another-subsubdir" ).getCanonicalPath
567+ new File (new File (dir, " another-subdir" ), " another-subsubdir" )
565568
566569 val dataInSubdir = Seq (1 , 2 , 3 ).toDF(" value" )
567570 val dataInSubsubdir = Seq (4 , 5 , 6 ).toDF(" value" )
@@ -570,20 +573,26 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils with Tes
570573 dataInSubdir.write
571574 .format (dataSourceName)
572575 .mode (SaveMode .Overwrite )
573- .save (subdir)
576+ .save (subdir.getCanonicalPath )
574577
575578 dataInSubsubdir.write
576579 .format (dataSourceName)
577580 .mode (SaveMode .Overwrite )
578- .save (subsubdir)
581+ .save (subsubdir.getCanonicalPath )
579582
580583 dataInAnotherSubsubdir.write
581584 .format (dataSourceName)
582585 .mode (SaveMode .Overwrite )
583- .save (anotherSubsubdir)
586+ .save (anotherSubsubdir.getCanonicalPath )
584587
585- /*
588+ require(subdir.exists)
589+ require(subdir.listFiles().exists(! _.isDirectory))
590+ require(subsubdir.exists)
591+ require(subsubdir.listFiles().exists(! _.isDirectory))
592+ require(anotherSubsubdir.exists)
593+ require(anotherSubsubdir.listFiles().exists(! _.isDirectory))
586594
595+ /*
587596 Directory structure generated
588597
589598 dir
@@ -620,7 +629,6 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils with Tes
620629 testWithPath(s " $dir/another*/* " , dataInAnotherSubsubdir)
621630 testWithPath(s " $dir/*/another* " , dataInAnotherSubsubdir)
622631 testWithPath(s " $dir/*/* " , dataInSubdir.union(dataInSubsubdir).union(dataInAnotherSubsubdir))
623-
624632 }
625633 }
626634
0 commit comments