-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-8756][SQL] Keep cached information and avoid re-calculating footers in ParquetRelation2 #7154
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
[SPARK-8756][SQL] Keep cached information and avoid re-calculating footers in ParquetRelation2 #7154
Changes from 4 commits
0ef8caf
186429d
12a0ed9
21bbdec
6ae0911
fa5458f
c2a2420
a52b6d1
c8fdfb7
ae0ec64
92e9347
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 |
|---|---|---|
|
|
@@ -342,15 +342,35 @@ private[sql] class ParquetRelation2( | |
| // Schema of the whole table, including partition columns. | ||
| var schema: StructType = _ | ||
|
|
||
| // Cached leaf statuses | ||
| var localCachedLeafStatuses: Set[FileStatus] = _ | ||
|
|
||
| var lastRefreshTime: Long = 0 | ||
|
|
||
| // Cached leaves | ||
| var cachedLeaves: Array[FileStatus] = Array() | ||
|
|
||
| /** | ||
| * Refreshes `FileStatus`es, footers, partition spec, and table schema. | ||
| */ | ||
| def refresh(): Unit = { | ||
| // Check if cachedLeafStatuses is changed or not | ||
| val leafStatusesChanged = localCachedLeafStatuses != cachedLeafStatuses() | ||
|
|
||
| // Lists `FileStatus`es of all leaf nodes (files) under all base directories. | ||
| val leaves = cachedLeafStatuses().filter { f => | ||
| isSummaryFile(f.getPath) || | ||
| !(f.getPath.getName.startsWith("_") || f.getPath.getName.startsWith(".")) | ||
| }.toArray | ||
| val leaves = if (leafStatusesChanged) { | ||
| localCachedLeafStatuses = cachedLeafStatuses() | ||
|
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. This is irrelevant to this PR, but I'd like to point out that this check is unnecessary now. IIRC, at the time PR #6012 was merged, |
||
| val updatedLeaves = cachedLeafStatuses().filter { f => | ||
| (isSummaryFile(f.getPath) || | ||
| !(f.getPath.getName.startsWith("_") || f.getPath.getName.startsWith("."))) && | ||
| (f.getModificationTime > lastRefreshTime) | ||
| }.toArray | ||
| lastRefreshTime = System.currentTimeMillis | ||
|
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. Using
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. We care about two kinds of files here:
|
||
| cachedLeaves = updatedLeaves | ||
|
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. We shouldn't drop |
||
| cachedLeaves | ||
| } else { | ||
| cachedLeaves | ||
| } | ||
|
|
||
| dataStatuses = leaves.filterNot(f => isSummaryFile(f.getPath)) | ||
| metadataStatuses = leaves.filter(_.getPath.getName == ParquetFileWriter.PARQUET_METADATA_FILE) | ||
|
|
||
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.
Should we do a deep copy here? Currently it's OK because
cachedLeafStatuses()always returns a new instance ofSet[FileStatus], but it's possible that we use a mutable set object in the future. In that case, the!=predicate above will always be true.