Skip to content

Merge a series of APPROX_PERCENTILE into a single ARRAY version #7

Description

@kaikalur

Presto has two versions of APPROX_PERCENTILE - one that produces a single percentile and another that produces an array of APPROX_PERCENTILE values. So when you see something like:

SELECT
APPROX_PERCENTILE(x, 0.1) AS percentile_10,
APPROX_PERCENTILE(x, 0.2) AS percentile_20,
APPROX_PERCENTILE(x, 0.3) AS percentile_30
FROM T

Rewrite it it:

SELECT
percentiles[1] AS percentile_10,
percentiles[2] AS percentile_20,
percentiles[3] AS percentile_30
FROM (
SELECT APPROX_PERCENTILE(x, ARRAY[0.1, 0.2, 0.3]) AS percentiles
FROM T
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions