-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-15248][SQL] Make MetastoreFileCatalog consider directories from partition specs of a partitioned metastore table #13022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,9 +54,16 @@ abstract class PartitioningAwareFileCatalog( | |
| } else { | ||
| prunePartitions(filters, partitionSpec()).map { | ||
| case PartitionDirectory(values, path) => | ||
| Partition( | ||
| values, | ||
| leafDirToChildrenFiles(path).filterNot(_.getPath.getName startsWith "_")) | ||
| val files: Seq[FileStatus] = leafDirToChildrenFiles.get(path) match { | ||
| case Some(existingDir) => | ||
| // Directory has children files in it, return them | ||
| existingDir.filterNot(_.getPath.getName.startsWith("_")) | ||
|
|
||
| case None => | ||
| // Directory does not exist, or has not children files | ||
| Nil | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the stacktrace in the description, how did we create the path of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran the test in this PR without the changes in source. |
||
| } | ||
| Partition(values, files) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -529,6 +529,40 @@ class ParquetMetastoreSuite extends ParquetPartitioningTest { | |
|
|
||
| dropTables("test_insert_parquet", "test_parquet_partitioned_cache_test") | ||
| } | ||
|
|
||
| test("SPARK-15248: explicitly added partitions should be readable") { | ||
| withTable("test_added_partitions", "test_temp") { | ||
| withTempDir { src => | ||
| val partitionDir = new File(src, "partition").getCanonicalPath | ||
| sql( | ||
| """ | ||
| |CREATE TABLE test_added_partitions (a STRING) | ||
| |PARTITIONED BY (b INT) | ||
| |STORED AS PARQUET | ||
| """.stripMargin) | ||
|
|
||
| // Temp table to insert data into partitioned table | ||
| Seq("foo", "bar").toDF("a").registerTempTable("test_temp") | ||
| sql("INSERT INTO test_added_partitions PARTITION(b='0') SELECT a FROM test_temp") | ||
|
|
||
| checkAnswer( | ||
| sql("SELECT * FROM test_added_partitions"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's avoid of using |
||
| Seq(("foo", 0), ("bar", 0)).toDF("a", "b")) | ||
|
|
||
| // Create partition without data files and check whether it can be read | ||
| sql(s"ALTER TABLE test_added_partitions ADD PARTITION (b='1') LOCATION '$partitionDir'") | ||
| checkAnswer( | ||
| sql("SELECT * FROM test_added_partitions"), | ||
| Seq(("foo", 0), ("bar", 0)).toDF("a", "b")) | ||
|
|
||
| // Add data files to partition directory and check whether they can be read | ||
| Seq("baz").toDF("a").write.mode(SaveMode.Overwrite).parquet(partitionDir) | ||
| checkAnswer( | ||
| sql("SELECT * FROM test_added_partitions"), | ||
| Seq(("foo", 0), ("bar", 0), ("baz", 1)).toDF("a", "b")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not --> no