-
Notifications
You must be signed in to change notification settings - Fork 1.5k
GH-3242: Emit and Read min/max statistics for int96 timestamp columns #3243
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
rahulketch
wants to merge
15
commits into
apache:master
Choose a base branch
from
rahulketch:int96-stats-imp
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 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0267c33
Add round trip int 96 stats test
rahulketch 9a6a205
ValidInt96Stats
rahulketch 91e47db
Add BINARY_AS_INT_96_COMPARATOR
rahulketch beb7ad3
Pass readInt96stats
rahulketch e1e2e8d
Compile correctly
rahulketch 26c3ddd
Fix more tests
rahulketch d65b7b8
Formatting
rahulketch 21bf8ae
Fix the comparator
rahulketch 43028d7
Merge branch 'master' into int96-stats-imp
rahulketch db9231c
BINARY_AS_INT_96_COMPARATOR -> BINARY_AS_INT96_TIMESTAMP_COMPARATOR
rahulketch 85f3c3c
Add clarification on the comparator
rahulketch 5eef533
Check parquet-mr version
rahulketch efacf01
Add slicing to fix bug with the comparator
rahulketch 2df49cb
Update parquet-column/src/main/java/org/apache/parquet/schema/Primiti…
rahulketch 90656f1
Update parquet-column/src/main/java/org/apache/parquet/ValidInt96Stat…
rahulketch 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
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
parquet-column/src/main/java/org/apache/parquet/ValidInt96Stats.java
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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.parquet; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import org.apache.parquet.VersionParser.ParsedVersion; | ||
| import org.apache.parquet.VersionParser.VersionParseException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Not all parquet writers populate the int96 statistics correctly. For example: arrow-rs | ||
| * https://github.com/apache/arrow-rs/blob/3ed9aedabc9e5a90170e43ff818f24a29eafb35b/parquet/src/file/statistics.rs#L212-L215 | ||
| * This class is used to detect whether a file was written with a version that has correct int96 statistics. | ||
| */ | ||
| public class ValidInt96Stats { | ||
| private static final AtomicBoolean alreadyLogged = new AtomicBoolean(false); | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(ValidInt96Stats.class); | ||
|
|
||
| /** | ||
| * Decides if the statistics from a file created by createdBy (the created_by field from parquet format) | ||
| * should be trusted for INT96 columns. | ||
| * | ||
| * @param createdBy the created-by string from a file footer | ||
| * @return true if the statistics are valid and can be trusted, false otherwise | ||
| */ | ||
| public static boolean hasValidInt96Stats(String createdBy) { | ||
| if (Strings.isNullOrEmpty(createdBy)) { | ||
| warnOnce("Cannot verify INT96 statistics because created_by is null or empty"); | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| ParsedVersion version = VersionParser.parse(createdBy); | ||
| if ("parquet-mr".equals(version.application)) { | ||
|
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. I recall that @rdblue has an opinion in maintaining an allow-list here. |
||
| return true; | ||
rahulketch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| if ("parquet-mr compatible Photon".equals(version.application)) { | ||
| return true; | ||
| } | ||
| } catch (RuntimeException | VersionParseException e) { | ||
| warnParseErrorOnce(createdBy, e); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static void warnParseErrorOnce(String createdBy, Throwable e) { | ||
| if (!alreadyLogged.getAndSet(true)) { | ||
rahulketch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LOG.warn("Cannot verify INT96 statistics because created_by could not be parsed: " + createdBy, e); | ||
| } | ||
| } | ||
|
|
||
| private static void warnOnce(String message) { | ||
| if (!alreadyLogged.getAndSet(true)) { | ||
| LOG.warn(message); | ||
| } | ||
| } | ||
| } | ||
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
57 changes: 57 additions & 0 deletions
57
parquet-column/src/test/java/org/apache/parquet/ValidInt96StatsTest.java
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.parquet; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class ValidInt96StatsTest { | ||
|
|
||
| @Test | ||
| public void testNullAndEmpty() { | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats(null)); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParquetMrValid() { | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3 (build abcd)")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3-SNAPSHOT")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3rc1")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3rc1-SNAPSHOT")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParquetMrCompatiblePhotonValid() { | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr compatible Photon version 1.0.0")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr compatible Photon version 1.0.0 (build abcd)")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr compatible Photon version 1.0.0-SNAPSHOT")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr compatible Photon version 1.0.0rc1")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr compatible Photon version 1.0.0rc1-SNAPSHOT")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInvalidApplications() { | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("arrow-rs version 0.1.0")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("impala version 1.6.0")); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.