fix(approx_fns): use exact percentile when no compression#21388
Open
aryan-212 wants to merge 2 commits intoapache:mainfrom
Open
fix(approx_fns): use exact percentile when no compression#21388aryan-212 wants to merge 2 commits intoapache:mainfrom
aryan-212 wants to merge 2 commits intoapache:mainfrom
Conversation
22718b8 to
e997594
Compare
40f862d to
95a4eff
Compare
95a4eff to
d8339ff
Compare
d8339ff to
4f86249
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The interpolation step assumes centroids represent clusters of multiple points. But if the number of input rows is small (≤ the digest's
max_size/ compression threshold), no compression ever happens: every centroid has weight 1 and corresponds to exactly one input value.In that regime, interpolation is not just unnecessary — it is actively wrong. The t-digest interpolates between adjacent centroids based on where the rank falls inside the centroid's weight, using half-deltas to neighbors. When every centroid has weight 1, this produces values that drift away from any actual data point.
This is particularly surprising for users running small queries or unit tests — they expect percentile functions on a handful of values to return one of those values.
(used gpt to frame this a bit properly)
Concrete Example
Lets take a small example from the TPCDS Schema
Now if we take a small
APPROX_PERCENTILEquery like:-From here,
0.85*14yields 11.9 or 12 so the output for the aboveAPPROX_PERCENITLEquery should be84336and that is what we get when we run the same query in DatabricksBut in Datafusion this comes up as
This PR aims to fix this.