Skip to content

[CALCITE-6767] PERCENTILE_CONT/PERCENTILE_DISC function are not supported#5095

Open
xuzifu666 wants to merge 2 commits into
apache:mainfrom
xuzifu666:calcite-6767
Open

[CALCITE-6767] PERCENTILE_CONT/PERCENTILE_DISC function are not supported#5095
xuzifu666 wants to merge 2 commits into
apache:mainfrom
xuzifu666:calcite-6767

Conversation

@xuzifu666

Copy link
Copy Markdown
Member


# [CALCITE-4644] Add PERCENTILE_CONT and PERCENTILE_DISC aggregate functions.
# PERCENTILE_CONT / PERCENTILE_DISC without GROUP BY.
select

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The result is validated in PostgreSQL in https://onecompiler.com/postgresql/44u4qdgpy and result is as expected

Comment thread core/src/test/resources/sql/agg.iq Outdated
!ok

# [CALCITE-6767] PERCENTILE_CONT/PERCENTILE_DISC syntax not supported.
# These sql was validated in PostgreSQL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sql -> sql programs
was -> were

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the remind, done.

final double rank = fraction * (n - 1);
final int lo = (int) Math.floor(rank);
final int hi = (int) Math.ceil(rank);
final double loValue = values.get(lo).doubleValue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this won't work for DECIMAL values with large precisions, since double has only 53 bits of mantissa, which is insufficient to store large decimal values without a large precision loss. If the decimals are close in values, the error will be very large.

I think using BigDecimal is probably a better approach.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense. I’ve updated the handling logic to use BigDecimal instead of double.

@sonarqubecloud

Copy link
Copy Markdown

@xuzifu666 xuzifu666 changed the title [CALCITE-6767] PERCENTILE_CONT/PERCENTILE_DISC syntax not supported [CALCITE-6767] PERCENTILE_CONT/PERCENTILE_DISC function are not supported Jul 14, 2026
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.

2 participants