-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-28098][SQL]Support read hive table while LeafDir had multi-level paths #32679
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 |
|---|---|---|
|
|
@@ -59,6 +59,9 @@ class InMemoryFileIndex( | |
| override val rootPaths = | ||
| rootPathsSpecified.filterNot(FileStreamSink.ancestorIsMetadataDirectory(_, hadoopConf)) | ||
|
|
||
| val readPartitionWithSubdirectoryEnabled = | ||
| sparkSession.sessionState.conf.readPartitionWithSubdirectoryEnabled | ||
|
|
||
| @volatile private var cachedLeafFiles: mutable.LinkedHashMap[Path, FileStatus] = _ | ||
| @volatile private var cachedLeafDirToChildrenFiles: Map[Path, Array[FileStatus]] = _ | ||
| @volatile private var cachedPartitionSpec: PartitionSpec = _ | ||
|
|
@@ -94,10 +97,23 @@ class InMemoryFileIndex( | |
| val files = listLeafFiles(rootPaths) | ||
| cachedLeafFiles = | ||
| new mutable.LinkedHashMap[Path, FileStatus]() ++= files.map(f => f.getPath -> f) | ||
| cachedLeafDirToChildrenFiles = files.toArray.groupBy(_.getPath.getParent) | ||
| cachedLeafDirToChildrenFiles = | ||
| if (readPartitionWithSubdirectoryEnabled) { | ||
| files.toArray.groupBy(file => getRootPathsLeafDir(file.getPath.getParent)) | ||
| } else { | ||
| files.toArray.groupBy(_.getPath.getParent) | ||
| } | ||
| cachedPartitionSpec = null | ||
| } | ||
|
|
||
| private def getRootPathsLeafDir(path: Path): Path = { | ||
| if (rootPaths.contains(path)) { | ||
| path | ||
| } else { | ||
| getRootPathsLeafDir(path.getParent) | ||
|
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. This fails with NPE if a parquet file is provided directly (instead of a directory). |
||
| } | ||
| } | ||
|
|
||
| override def equals(other: Any): Boolean = other match { | ||
| case hdfs: InMemoryFileIndex => rootPaths.toSet == hdfs.rootPaths.toSet | ||
| case _ => false | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -520,6 +520,22 @@ class FileIndexSuite extends SharedSparkSession { | |
| SQLConf.get.setConf(StaticSQLConf.METADATA_CACHE_TTL_SECONDS, previousValue) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-28098 - supporting read partitioned Hive tables with subdirectories") { | ||
|
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. not sure what this is testing for this case also passes on 2.4 without any patched code |
||
| withTempPath { dir => | ||
| spark | ||
| .range(2) | ||
| .select(col("id").as("p"), col("id")) | ||
| .write | ||
| .partitionBy("p") | ||
| .orc(s"${dir.getAbsolutePath}/sub1/sub2") | ||
| val path = new Path(dir.getAbsolutePath) | ||
| val fileIndex = new InMemoryFileIndex(spark, Seq(path), Map.empty, None) | ||
| val partitionValues = fileIndex.partitionSpec().partitions.map(_.values) | ||
| assert(partitionValues.length == 2 && partitionValues(0).numFields == 1 && | ||
| partitionValues(1).numFields == 1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object DeletionRaceFileSystem { | ||
|
|
||
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.
I found that here can not infer partition for non-catalog table. For table location /dir/table/pt=1/file, here the key is
/dir/table, the value is/dir/table/pt=1/file. So we can not infer partition from the key/dir/table.