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

Ensure partition function never return negative partition #8221

Merged

Conversation

Jackie-Jiang
Copy link
Contributor

There are some corner cases not handled in partition function which can lead to negative partition:

  • In HashCodePartitionFunction when hashcode is Integer.MIN_VALUE
  • In ModuloPartitionFunction when value is negative

Also enhance the test to ensure passing number and string returns the same result

@@ -57,4 +56,8 @@ public int getNumPartitions() {
public String toString() {
return NAME;
}

private int abs(int n) {
return (n == Integer.MIN_VALUE) ? 0 : Math.abs(n);
Copy link
Member

Choose a reason for hiding this comment

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

this is equivalent to Math.abs(n) & Integer.MAX_VALUE but the callers could just move the modulo inside the Math.abs to avoid dealing with Integer.MIN_VALUE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. This is the same as ByteArrayPartitionFunction, so I'll also change that

@Jackie-Jiang Jackie-Jiang force-pushed the partition_function_negative_handling branch from e843754 to b316b73 Compare February 18, 2022 01:30
@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2022

Codecov Report

Merging #8221 (3ca6b92) into master (287f552) will increase coverage by 0.02%.
The diff coverage is 87.50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #8221      +/-   ##
============================================
+ Coverage     71.01%   71.04%   +0.02%     
+ Complexity     4320     4319       -1     
============================================
  Files          1626     1626              
  Lines         85067    85067              
  Branches      12799    12799              
============================================
+ Hits          60408    60433      +25     
+ Misses        20505    20474      -31     
- Partials       4154     4160       +6     
Flag Coverage Δ
integration1 28.84% <0.00%> (+0.08%) ⬆️
integration2 27.49% <0.00%> (+0.05%) ⬆️
unittests1 67.34% <87.50%> (-0.01%) ⬇️
unittests2 14.13% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...gment/spi/partition/HashCodePartitionFunction.java 66.66% <50.00%> (-11.12%) ⬇️
...ment/spi/partition/ByteArrayPartitionFunction.java 66.66% <100.00%> (ø)
...segment/spi/partition/ModuloPartitionFunction.java 68.75% <100.00%> (+2.08%) ⬆️
...segment/spi/partition/MurmurPartitionFunction.java 93.54% <100.00%> (+2.92%) ⬆️
...er/validation/BrokerResourceValidationManager.java 81.25% <0.00%> (-18.75%) ⬇️
...ache/pinot/core/operator/docidsets/OrDocIdSet.java 86.36% <0.00%> (-11.37%) ⬇️
...nction/DistinctCountBitmapAggregationFunction.java 51.81% <0.00%> (-3.63%) ⬇️
...lix/core/realtime/PinotRealtimeSegmentManager.java 79.58% <0.00%> (-3.15%) ⬇️
...e/impl/forward/FixedByteMVMutableForwardIndex.java 90.90% <0.00%> (-3.04%) ⬇️
.../org/apache/pinot/core/startree/StarTreeUtils.java 69.89% <0.00%> (-2.16%) ⬇️
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 287f552...3ca6b92. Read the comment docs.

@Jackie-Jiang Jackie-Jiang force-pushed the partition_function_negative_handling branch from b316b73 to 3ca6b92 Compare February 18, 2022 20:22
@snleee
Copy link
Contributor

snleee commented Feb 18, 2022

If this is a backward incompatible change (especially forModuloPartitionFunction), please tag accordingly.

@Jackie-Jiang
Copy link
Contributor Author

@snleee This is not. For modulo, it only fixes the partition if it is negative before, which is not working anyway.

@Jackie-Jiang Jackie-Jiang merged commit 21632da into apache:master Feb 21, 2022
@Jackie-Jiang Jackie-Jiang deleted the partition_function_negative_handling branch February 21, 2022 17:56
xiangfu0 pushed a commit to xiangfu0/pinot that referenced this pull request Feb 23, 2022
There are some corner cases not handled in partition function which can lead to negative partition:
- In HashCodePartitionFunction when hashcode is Integer.MIN_VALUE
- In ModuloPartitionFunction when value is negative

Also enhance the test to ensure passing number and string returns the same result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants