-
Notifications
You must be signed in to change notification settings - Fork 1.6k
GH-3696: Cache ParsedVersion in FileMetaData and use it in fromParquetMetadata #3700
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
Open
asifsmohammed
wants to merge
4
commits into
apache:master
Choose a base branch
from
asifsmohammed:gh-3696-cache-parsed-version
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bc23cf5
GH-3696: Cache ParsedVersion in FileMetaData to eliminate redundant p…
asifsmohammed 51ca7b7
Address review: lazy init for writerVersion
asifsmohammed b6a87de
Address review: use immutable WriterVersionResult with lazy synchroni…
asifsmohammed 6973b84
Use cached ParsedVersion in fromParquetMetadata
asifsmohammed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,10 @@ | |
| import java.io.Serializable; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import org.apache.parquet.Strings; | ||
| import org.apache.parquet.VersionParser; | ||
| import org.apache.parquet.VersionParser.ParsedVersion; | ||
| import org.apache.parquet.VersionParser.VersionParseException; | ||
| import org.apache.parquet.crypto.InternalFileDecryptor; | ||
| import org.apache.parquet.schema.MessageType; | ||
|
|
||
|
|
@@ -39,9 +43,22 @@ public enum EncryptionType { | |
| ENCRYPTED_FOOTER | ||
| } | ||
|
|
||
| private static final class WriterVersionResult { | ||
| private final ParsedVersion version; | ||
| private final VersionParseException versionParseException; | ||
|
|
||
| static final WriterVersionResult MISSING = new WriterVersionResult(null, null); | ||
|
|
||
| WriterVersionResult(ParsedVersion version, VersionParseException versionParseException) { | ||
| this.version = version; | ||
| this.versionParseException = versionParseException; | ||
| } | ||
| } | ||
|
|
||
| private final MessageType schema; | ||
| private final Map<String, String> keyValueMetaData; | ||
|
Member
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 cached field is |
||
| private final String createdBy; | ||
| private transient volatile WriterVersionResult writerVersionResult; | ||
| private final InternalFileDecryptor fileDecryptor; | ||
| private final EncryptionType encryptionType; | ||
|
|
||
|
|
@@ -118,4 +135,40 @@ public InternalFileDecryptor getFileDecryptor() { | |
| public EncryptionType getEncryptionType() { | ||
| return encryptionType; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the parsed writer version from the {@code createdBy} string. The result is | ||
| * computed lazily and cached. | ||
| * | ||
| * @return the parsed version, or {@code null} if {@code createdBy} is null or empty | ||
| * @throws VersionParseException if {@code createdBy} is present but cannot be parsed | ||
| */ | ||
| @JsonIgnore | ||
| public ParsedVersion getWriterVersion() throws VersionParseException { | ||
| WriterVersionResult result = writerVersionResult; | ||
| if (result == null) { | ||
| synchronized (this) { | ||
| result = writerVersionResult; | ||
| if (result == null) { | ||
| result = parseCreatedBy(); | ||
| writerVersionResult = result; | ||
| } | ||
| } | ||
| } | ||
| if (result.versionParseException != null) { | ||
| throw result.versionParseException; | ||
| } | ||
| return result.version; | ||
| } | ||
|
|
||
| private WriterVersionResult parseCreatedBy() { | ||
| if (Strings.isNullOrEmpty(createdBy)) { | ||
| return WriterVersionResult.MISSING; | ||
| } | ||
| try { | ||
| return new WriterVersionResult(VersionParser.parse(createdBy), null); | ||
| } catch (VersionParseException e) { | ||
| return new WriterVersionResult(null, e); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ParsedVersioneagerly parses and caches theSemanticVersionin its constructor, sogetSemanticVersion()avoids the redundantSemanticVersion.parse(version.version)that the String-based overload previously performed on every call. The left and right spikes in flame graph are for parsingSemanticVersiontwice.