You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flink.apache.org by "Dylan He (Jira)" <ji...@apache.org> on 2024/08/21 11:43:00 UTC

[jira] [Created] (FLINK-36123) Add PERCENTILE function

Dylan He created FLINK-36123:
--------------------------------

             Summary: Add PERCENTILE function
                 Key: FLINK-36123
                 URL: https://issues.apache.org/jira/browse/FLINK-36123
             Project: Flink
          Issue Type: Sub-task
          Components: Table SQL / API
            Reporter: Dylan He


Add PERCENTILE function.
----
Return a percentile value based on a continuous distribution of the input column. If no input row lies exactly at the desired percentile, the result is calculated using linear interpolation of the two nearest input values. NULL values are ignored in the calculation.

Example:
{code:sql}
> SELECT PERCENTILE(col, 0.3) FROM VALUES (0), (10), (10) AS tab(col);
 6.0
> SELECT PERCENTILE(col, array(0.25, 0.75)) FROM VALUES (0), (10) AS tab(col);
 [2.5,7.5]
{code}

Syntax:
{code:sql}
PERCENTILE(expr, percentage)
{code}

Arguments:
 * {{expr}}: A NUMERIC expression.
 * {{percentage}}: A NUMERIC expression between 0 and 1 or an ARRAY of NUMERIC expressions, each between 0 and 1.

Returns:
DOUBLE if percentage is numeric, or an ARRAY of DOUBLE if percentage is an ARRAY.

See also:
 * [Hive|https://cwiki.apache.org/confluence/display/hive/languagemanual+udf#LanguageManualUDF-Built-inAggregateFunctions(UDAF)]
 * [Spark|https://spark.apache.org/docs/3.5.1/sql-ref-functions-builtin.html#mathematical-functions]
 * [Databricks|https://docs.databricks.com/en/sql/language-manual/functions/percentile.html]
 * [PostgreSQL|https://www.postgresql.org/docs/16/functions-aggregate.html] percentile_cont
 * [Snowflake|https://docs.snowflake.com/en/sql-reference/functions/percentile_cont]
 * [Oracle|https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/PERCENTILE_CONT.html]
 * [Wiki|https://en.wikipedia.org/wiki/Percentile]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)