Skip to content

FILTER Clause for Aggregate Functions #5873

@yjshen

Description

@yjshen

Is your feature request related to a problem or challenge?

Implement the FILTER clause for aggregate functions (introduced in SQL:2003). This syntax allows for filtering before aggregation.

SUM(<expression>) FILTER(WHERE <condition>)

Describe the solution you'd like

Have the filter support directly in our AggregateExec.

Describe alternatives you've considered

Rewrite the filter clause for aggregate functions to use the CASE WHEN expression during planning. However, null handling for each aggregator function regarding the filter would be error-prone.

Additional context

PostgreSQL: https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-AGGREGATES
Spark: https://spark.apache.org/docs/3.3.2/sql-ref-syntax-qry-select-groupby.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions