-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Make totalRecordCount optional in PartitionStats #12226
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ba9101
Core: Make totalRecordCount optional in PartitionStats
ajantha-bhat 79e3b40
update version
ajantha-bhat 3f49981
Fix test failure after rebase
ajantha-bhat 9cfe5ab
Rename and fix test after rebase
ajantha-bhat 91637db
Address comments
ajantha-bhat e4a6033
Add tests
ajantha-bhat 7b288e8
Update core/src/main/java/org/apache/iceberg/PartitionStats.java
nastra 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
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
135 changes: 135 additions & 0 deletions
135
core/src/test/java/org/apache/iceberg/TestPartitionStats.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,135 @@ | ||
| /* | ||
| * 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.iceberg; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import org.apache.iceberg.types.Types; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class TestPartitionStats { | ||
|
|
||
| private static final PartitionData PARTITION = | ||
| new PartitionData( | ||
| Types.StructType.of(Types.NestedField.required(1, "foo", Types.IntegerType.get()))); | ||
|
|
||
| @Test | ||
| public void testAppendWithAllValues() { | ||
| PartitionStats stats1 = | ||
| createStats(100L, 15, 1000L, 2L, 500, 1L, 200, 15L, 1625077800000L, 12345L); | ||
| PartitionStats stats2 = createStats(200L, 7, 500L, 1L, 100, 0L, 50, 7L, 1625077900000L, 12346L); | ||
|
|
||
| stats1.appendStats(stats2); | ||
|
|
||
| validateStats(stats1, 300L, 22, 1500L, 3L, 600, 1L, 250, 22L, 1625077900000L, 12346L); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendWithThisNullOptionalField() { | ||
| PartitionStats stats1 = createStats(100L, 15, 1000L, 2L, 500, 1L, 200, null, null, null); | ||
| PartitionStats stats2 = createStats(100L, 7, 500L, 1L, 100, 0L, 50, 7L, 1625077900000L, 12346L); | ||
|
|
||
| stats1.appendStats(stats2); | ||
|
|
||
| validateStats(stats1, 200L, 22, 1500L, 3L, 600, 1L, 250, 7L, 1625077900000L, 12346L); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendWithBothNullOptionalFields() { | ||
| PartitionStats stats1 = createStats(100L, 15, 1000L, 2L, 500, 1L, 200, null, null, null); | ||
| PartitionStats stats2 = createStats(100L, 7, 500L, 1L, 100, 0L, 50, null, null, null); | ||
|
|
||
| stats1.appendStats(stats2); | ||
|
|
||
| validateStats(stats1, 200L, 22, 1500L, 3L, 600, 1L, 250, null, null, null); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendWithOtherNullOptionalFields() { | ||
| PartitionStats stats1 = | ||
| createStats(100L, 15, 1000L, 2L, 500, 1L, 200, 15L, 1625077900000L, 12346L); | ||
| PartitionStats stats2 = createStats(100L, 7, 500L, 1L, 100, 0L, 50, null, null, null); | ||
|
|
||
| stats1.appendStats(stats2); | ||
|
|
||
| validateStats(stats1, 200L, 22, 1500L, 3L, 600, 1L, 250, 15L, 1625077900000L, 12346L); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendEmptyStats() { | ||
| PartitionStats stats1 = new PartitionStats(PARTITION, 1); | ||
| PartitionStats stats2 = new PartitionStats(PARTITION, 1); | ||
|
|
||
| stats1.appendStats(stats2); | ||
|
|
||
| validateStats(stats1, 0L, 0, 0L, 0L, 0, 0L, 0, null, null, null); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendWithDifferentSpec() { | ||
| PartitionStats stats1 = new PartitionStats(PARTITION, 1); | ||
| PartitionStats stats2 = new PartitionStats(PARTITION, 2); | ||
|
|
||
| assertThatThrownBy(() -> stats1.appendStats(stats2)) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessage("Spec IDs must match"); | ||
| } | ||
|
|
||
| private PartitionStats createStats( | ||
| long dataRecordCount, | ||
| int dataFileCount, | ||
| long totalDataFileSizeInBytes, | ||
| long positionDeleteRecordCount, | ||
| int positionDeleteFileCount, | ||
| long equalityDeleteRecordCount, | ||
| int equalityDeleteFileCount, | ||
| Long totalRecordCount, | ||
| Long lastUpdatedAt, | ||
| Long lastUpdatedSnapshotId) { | ||
|
|
||
| PartitionStats stats = new PartitionStats(PARTITION, 1); | ||
ajantha-bhat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| stats.set(2, dataRecordCount); | ||
| stats.set(3, dataFileCount); | ||
| stats.set(4, totalDataFileSizeInBytes); | ||
| stats.set(5, positionDeleteRecordCount); | ||
| stats.set(6, positionDeleteFileCount); | ||
| stats.set(7, equalityDeleteRecordCount); | ||
| stats.set(8, equalityDeleteFileCount); | ||
| stats.set(9, totalRecordCount); | ||
| stats.set(10, lastUpdatedAt); | ||
| stats.set(11, lastUpdatedSnapshotId); | ||
|
|
||
| return stats; | ||
| } | ||
|
|
||
| private void validateStats(PartitionStats stats, Object... expectedValues) { | ||
| // Spec id and partition data should be unchanged | ||
| assertThat(stats.get(0, PartitionData.class)).isEqualTo(PARTITION); | ||
| assertThat(stats.get(1, Integer.class)).isEqualTo(1); | ||
|
|
||
| for (int i = 0; i < expectedValues.length; i++) { | ||
| if (expectedValues[i] == null) { | ||
| assertThat(stats.get(i + 2, Object.class)).isNull(); | ||
| } else { | ||
| assertThat(stats.get(i + 2, Object.class)).isEqualTo(expectedValues[i]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
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.
do we really need to deprecate the existing method and introduce a new one to handle this properly? I'm not a fan of having a method with
optionalin the name. Also what if the field itself becomes aLongbut the method's return type stays the same?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.
Maybe no one using it as the writer code is not present in previous version.
But just following the guidelines as it is a public interface and introduced in previous version.
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.
We wanted to return null when not computed as per the discussion. We can't do that if the return type is primitive.