-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Data: Add partition stats writer and reader #11216
base: main
Are you sure you want to change the base?
Conversation
941505a
to
05a80f6
Compare
core/src/main/java/org/apache/iceberg/data/PartitionStatsRecord.java
Outdated
Show resolved
Hide resolved
Schema schema, | ||
PartitionSpec spec, | ||
int formatVersion, | ||
Map<String, String> properties) { |
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.
There was no option to pass the table properties before.
Needed to pass different file format for paramterized test.
@aokolnychyi: This PR is ready. But as we discussed previously, this PR wraps the I will explore adding the internal writers for Parquet and Orc. Similar to #11108. |
@RussellSpitzer: It would be good to have this in 1.7.0. |
I already tried POC for internal writers on another branch, The problems: b) Also, Using partitionData in StructLikeMap is not working fine. Some keys are missing in the map (looks like equals() logic), If I use Record, it is fine. Maybe in the next version we can have optimized writer and reader (without converter using internal reader and writers). |
data/src/test/java/org/apache/iceberg/data/TestPartitionStatsHandler.java
Outdated
Show resolved
Hide resolved
Moving out of 1.7.0 since we still have a bit of discussion here |
05a80f6
to
ee3b273
Compare
@RussellSpitzer: I have added the Assertion for Partition type as you suggested and replied to #11216 (comment), do you have anymore comments for this PR? |
I had a conversation with @rdblue today about internal writers. Ryan should have a bit of time to help/guide. |
data/src/main/java/org/apache/iceberg/data/PartitionStatsHandler.java
Outdated
Show resolved
Hide resolved
@RussellSpitzer @aokolnychyi I'm reviewing the stale PRs, and this one is open for month. Do we have a way to move forward ? I can do a new review, but at the end of the day, it won't help for the merge (as only committers can merge PR). |
Thanks @ajantha-bhat for your work on partition stats support in Iceberg! That could be reused in Hive as a building block for apache/hive#5498 |
@danielcweeks @RussellSpitzer @aokolnychyi would you have some time to take a look on this PR and my proposal (previous comment) ? |
I just found this PR as I'm desperately looking for this functionality. Thanks @ajantha-bhat! Let's see if the review gets wrapped soon 🤞 |
* @param branch A branch information to select the required snapshot. | ||
* @return {@link PartitionStatisticsFile} for the given branch. | ||
*/ | ||
public static PartitionStatisticsFile computeAndWriteStatsFile(Table table, String branch) { |
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.
Wouldn't it be better not to have fat methods with multiple responsibilities? What if we introduce the write method that gets the stats iterator as an argument.
We might not need to execute the complete stats rebuild for all the registered partitions, but only for those that were changed in the current snapshot.
Snapshot summary already has a metric for the number of changed partitions, maybe we could extend it with the partition list and re-compute stats only for them. Then generate a new stats file based on the prev snapshot stats with updates to the changed partitions.
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.
What if we introduce the write method that gets the stats iterator as an argument.
We do have a package-private write method for that writePartitionStatsFile
, just have to make it public.
Didn't do because what if the users don't sort the stats before, it will violate the spec.
hi @ajantha-bhat, could you please check below: it seems that Date, time, timestamp partition values are not properly serialized
PartitionSpec.partitionToPath(PartitionStatsRecord.unwrap().partition()) thows an exception
I think, instead of Record(1999-12-31) it should be Record{10956} full code snippet
|
@deniskuzZ: Thanks for testing out. We are working on Internal parquet/Avro/orc readers and writes. partition stats will use them. So, we don't need to go through these converters. I will retest all the data types once I use internal writers for partition stats. |
ee3b273
to
289957f
Compare
|
||
@SuppressWarnings("checkstyle:CyclomaticComplexity") | ||
public static boolean isEqual( | ||
Comparator<StructLike> partitionComparator, PartitionStats stats1, PartitionStats stats2) { |
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.
Cannot have Equals
and HashCode
for PartitionStats
class as StructLike
need to have comparator for equals()
which forces that class extends StructLike
to hold some more things. Setting comparator while serializing and deserializing that class will be a mess.
Hence, added this util method. Currently used only by tests. But can be useful for developers when they integrate partition stats to engines, they can use it for their tests. So, kept as a util.
289957f
to
e1a4e89
Compare
@aokolnychyi, @rdblue, @RussellSpitzer: I have reworked on the PR to use Internal writers and readers. PR is much simpler and no need to handle those conversions now. I can rebase it once the Parquet internal writer PR is merged. @deniskuzZ : Feel free to test the latest state. It doesn't have conversion layer. So, should behave as expected now. |
hi @ajantha-bhat, i need to include #11919, anything else? |
e1a4e89
to
0668d6a
Compare
0668d6a
to
dd2c45a
Compare
@aokolnychyi, @rdblue, @RussellSpitzer: I have worked on Internal writers, readers for Avro, parquet and PRs got merged. So, this PR is very simple now (no converter logic) and it just writes stats to a file. I think if we get a good review support it can be merged for 1.8.0 itself. Please take a look. |
hi @ajantha-bhat, what is the purpose of |
@deniskuzZ: While designing the spec (https://iceberg.apache.org/spec/#partition-statistics-file), we have added
Let us wait for the merge of this PR. After that we can open the discussion to add additional stats for partition stats spec. For example some folks want min max stats also #11083. |
Ping. |
data/src/main/java/org/apache/iceberg/data/PartitionStatsHandler.java
Outdated
Show resolved
Hide resolved
dd2c45a
to
4945ec1
Compare
PartitionStatisticsFile partitionStatisticsFile = | ||
PartitionStatsHandler.computeAndWriteStatsFile(testTable, "b1"); | ||
// creates an empty stats file since the dummy snapshot exist | ||
assertThat(partitionStatisticsFile.fileSizeInBytes()).isEqualTo(0L); |
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.
test would be broken if default format changes, for example with avro format non-zero file would be created
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.
But it won't be flaky. So, we can update the test if the behavior changes. This is as per current behavior.
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.
true, I've already added +1
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.
Thanks for your reviews. I hope we ship this feature soon and glad to know Hive, Trino are waiting for this feature.
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.
LGTM, could we please get this merged? @pvary, would you be able to help
Introduce APIs to write the partition stats into files in table default format using Iceberg generic writers and readers.