embucket-labs icon indicating copy to clipboard operation
embucket-labs copied to clipboard

Support multiple `WITHIN GROUP` in query

Open Vedin opened this issue 6 months ago • 0 comments

Example of a supported Snowflake query but not supported with the current Datafusion: Only a single ordering expression is permitted in a WITHIN GROUP clause in datafusion/sql/src/expr/function.rs

SELECT 
        category,
        LISTAGG(name, ', ') WITHIN GROUP (ORDER BY price ASC, name DESC) AS price_asc_name_desc,
        LISTAGG(DISTINCT name, ' -> ') WITHIN GROUP (ORDER BY name) AS distinct_names
    FROM (VALUES 
        ('fruit', 'apple', 1.20), 
        ('fruit', 'banana', 0.80), 
        ('fruit', 'apple', 1.20),
        ('vegetable', 'carrot', 0.90), 
        ('vegetable', 'broccoli', 2.10),
        ('vegetable', 'carrot', 0.90)
    ) AS t(category, name, price) 
    GROUP BY category 
    ORDER BY category

Vedin avatar Jun 05 '25 19:06 Vedin