Skip to content
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

Flink: a few small fixes or tuning for range partitioner #10823

Merged
merged 3 commits into from
Aug 1, 2024

Conversation

stevenzwu
Copy link
Contributor

@stevenzwu stevenzwu commented Jul 30, 2024

  • handle empty stats (like no traffic)
  • use struct comparator with transformed schema for SortKey
  • also added more unit tests.

The next PR after this would be putting everything together in FlinkSink and document update.

@@ -47,18 +46,6 @@ class SketchRangePartitioner implements Partitioner<RowData> {
public int partition(RowData row, int numPartitions) {
// reuse the sortKey and rowDataWrapper
sortKey.wrap(rowDataWrapper.wrap(row));
int partition = Arrays.binarySearch(rangeBounds, sortKey, comparator);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this refactoring is to make it easier to write unit test with the static util method

@@ -91,7 +91,7 @@ class DataStatisticsCoordinator implements OperatorCoordinator {
this.context = context;
this.schema = schema;
this.sortOrder = sortOrder;
this.comparator = SortOrderComparators.forSchema(schema, sortOrder);
this.comparator = Comparators.forType(SortKeyUtil.sortKeySchema(schema, sortOrder).asStruct());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an important fix. SortKey may have been serialized by subtask and deserialized by the coordinator. we need to use the schema of the transformed sort fields for struct comparator.

new SortKey[] {CHAR_KEYS.get("c"), CHAR_KEYS.get("j"), CHAR_KEYS.get("m")};

// <= c
assertThat(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code duplicated in the next method? Is there a way to extract the duplicated code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some duplications. but I think those two tests are different: scale up and scale down. I want to explicitly test each range.

The scale down case has this differently.

// > m
    // reassigns out-of-range partitions via mod (% 3 in this case)
    assertThat(
            SketchUtil.partition(
                CHAR_KEYS.get("n"), numPartitions, rangeBounds, SORT_ORDER_COMPARTOR))
        .isEqualTo(0);
    assertThat(
            SketchUtil.partition(
                CHAR_KEYS.get("z"), numPartitions, rangeBounds, SORT_ORDER_COMPARTOR))
        .isEqualTo(0);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a method like this would help to focus on the actual test and hide the common parameters?

private static assertPartition(SortKey key, int expected) {
   assertThat(
            SketchUtil.partition(
                key, numPartitions, rangeBounds, SORT_ORDER_COMPARTOR))
        .isEqualTo(expected);
}

The first 8 assertions seems like the same to me, but it is hard to check/understand as it is "hidden" by the long assertion statements.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a good idea. Reducing to a single line would help readability.

@stevenzwu stevenzwu merged commit 6e7113a into apache:main Aug 1, 2024
24 checks passed
@stevenzwu
Copy link
Contributor Author

thanks @pvary for the review. will create the back port PR shortly

@stevenzwu stevenzwu deleted the range-partitioner-fixup branch August 1, 2024 21:11
stevenzwu added a commit to stevenzwu/iceberg that referenced this pull request Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants