Skip to content

Conversation

@sgrebnov
Copy link

@sgrebnov sgrebnov commented Oct 13, 2024

Which issue does this PR close?

PR improves Window function unparsing with aggregation when aggregation functions present in When/Then and Order By parts.

For example case when grouping(i_class) = 0 then i_category end and order by sum(ws_net_paid) desc in Window rank():

select
    sum(ws_net_paid) as total_sum
   ,i_category
   ,i_class
   ,grouping(i_category)+grouping(i_class) as lochierarchy
   ,rank() over (
 	partition by grouping(i_category)+grouping(i_class),
 	case when grouping(i_class) = 0 then i_category end
 	order by sum(ws_net_paid) desc) as rank_within_parent
 from
    web_sales
   ,date_dim       d1
   ,item
 where
    d1.d_month_seq between 1205 and 1205+11
 and d1.d_date_sk = ws_sold_date_sk
 and i_item_sk  = ws_item_sk
 group by rollup(i_category,i_class)
 order by
   lochierarchy desc,
   case when lochierarchy = 0 then i_category end,
   rank_within_parent
  LIMIT 100;

Fixes

@sgrebnov sgrebnov merged commit 1f0edf0 into spiceai-42 Oct 13, 2024
@sgrebnov sgrebnov deleted the sgrebnov/improve-agg-unparsing branch October 13, 2024 20:12
Sevenannn pushed a commit that referenced this pull request Oct 26, 2024
…regation (apache#12946)

* Improve unparsing for ORDER BY with Aggregation functions (#38)

* Improve UNION unparsing (#39)

* Scalar functions in ORDER BY unparsing support (#41)

* Improve unparsing for complex Window functions with Aggregation (#42)

* WindowFunction order_by should respect `supports_nulls_first_in_sort` dialect setting (#43)

* Fix plan_to_sql

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants