-
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 #3590
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
base: master
Are you sure you want to change the base?
Changes from all commits
0267c33
9a6a205
91e47db
beb7ad3
e1e2e8d
26c3ddd
d65b7b8
21bf8ae
43028d7
db9231c
85f3c3c
5eef533
efacf01
2df49cb
90656f1
6981ffb
ad7c4ec
f49635d
5cd918f
31e8196
5173dcd
dc2197f
beff689
c47d7b4
519c544
43e0c29
61bc607
8b3e37a
f3e9f7c
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 |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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); | ||
|
|
||
| private static final SemanticVersion MINIMUM_PARQUET_MR_VERSION = new SemanticVersion(1, 16, 0); | ||
|
|
||
| /** | ||
| * 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 | ||
| */ | ||
|
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. Having an allow-list on createdBy was discussed in the mailing list: https://lists.apache.org/thread/6t9fr6v602zwt0tw22bqwg81f1ny9ncj
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. I actually don't necessarily think lazy consensus was reached. I would ping the mailing list and note the proposed PR moving forward with an allow list. |
||
| 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)) { | ||
| return version.hasSemanticVersion() | ||
| && version.getSemanticVersion().compareTo(MINIMUM_PARQUET_MR_VERSION) >= 0; | ||
| } | ||
| 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)) { | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * 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.16.0")); | ||
|
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. tests need to be updated. |
||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.16.1")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 2.0.0")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.16.0 (build abcd)")); | ||
| assertTrue(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.16.1-SNAPSHOT")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParquetMrInvalid() { | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.15.0")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.15.1")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.15.1-SNAPSHOT")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.16.0-SNAPSHOT")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.14.0")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3 (build abcd)")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3-SNAPSHOT")); | ||
| assertFalse(ValidInt96Stats.hasValidInt96Stats("parquet-mr version 1.12.3rc1")); | ||
| assertFalse(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")); | ||
| } | ||
| } | ||
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.
this needs to be 18 now?