Skip to content

Support column reference as percentile arg for percentile_cont and approx_percentile_cont #24337

Description

@dd-annarose

Is your feature request related to a problem or challenge?

percentile_cont and approx_percentile_cont only accept a literal for the percentile argument (see here).

We could extend support for column reference or projections as well.

Describe the solution you'd like

Add support for ColumnarValue::Array for both percentile_cont and approx_percentile_cont.

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. dd-annarose commented on Aug 13, 2026

    @dd-annarose
    ContributorAuthor

    take

  2. Jefffrey commented on Aug 20, 2026

    @Jefffrey
    Contributor

    what would be the behaviour if it supports ColumnarValue::Array for the percentile? or is this assuming the array is len 1 anyway, akin to a scalar?

  3. dd-annarose commented on Sep 11, 2026

    @dd-annarose
    ContributorAuthor

    @Jefffrey We're hitting an issue when the percentile comes from a projection. The behavior would be the same as for Trino: the percentile argument must be constant for all inputs. So yes, essentially it would be a ScalarValue (not always folded into a ScalarValue).

    does that seem reasonable to you?

  4. Jefffrey commented on Sep 15, 2026

    @Jefffrey
    Contributor

    pub(crate) fn get_scalar_value(expr: &Arc<dyn PhysicalExpr>) -> Result<ScalarValue> {
    let empty_schema = Arc::new(Schema::empty());
    let batch = RecordBatch::new_empty(Arc::clone(&empty_schema));
    if let ColumnarValue::Scalar(s) = expr.evaluate(&batch)? {
    Ok(s)
    } else {
    internal_err!("Didn't expect ColumnarValue::Array")
    }
    }
    /// Validates that a percentile expression is a literal float value between 0.0 and 1.0.
    ///
    /// Used by both `percentile_cont` and `approx_percentile_cont` to validate their
    /// percentile parameters.
    pub(crate) fn validate_percentile_expr(
    expr: &Arc<dyn PhysicalExpr>,
    fn_name: &str,
    ) -> Result<f64> {
    let scalar_value = get_scalar_value(expr).map_err(|_e| {

    so is this about fixing line 33 here to potentially accept a ColumnarValue::Array with length 1? Since for some reason its not coming as a ColumnarValue::Scalar?

  5. dd-annarose commented on Sep 15, 2026

    @dd-annarose
    ContributorAuthor

    @Jefffrey Not exactly: this is not sufficient because you can have empty batches and then would not be able to resolve the percentile argument.

  6. added a commit that references this issue on Oct 21, 2026
    9504942
  7. added a commit that references this issue on Oct 22, 2026
    2e0fa9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions