Skip to content

Conversation

@sgrebnov
Copy link

@sgrebnov sgrebnov commented Oct 10, 2024

Which issue does this PR close?

Fix UNION unparsing for queries where UNION is a subquery. This fixes unparsing for TPC-DS Q80, Q76, Q77, Q33, Q66

Original query

select
	channel,
	col_name
from
	(
	select
		'store' as channel,
		'ss_customer_sk' as col_name
	from
		store_sales
union all
	select
		'web' as channel,
		'ws_ship_hdemo_sk' as col_name
	from
		web_sales
    ) as foo
group by
	channel,
	col_name
order by
	channel,
	col_name

Before (invalid):

select
	'store' as "channel",
	'ss_customer_sk' as "col_name"
from
	"store_sales"
union all
select
	'web' as "channel",
	'ws_ship_hdemo_sk' as "col_name"
from
	"web_sales"
order by
	"foo"."channel" asc nulls last,
	"foo"."col_name" asc nulls last

After (correct)

select
	"foo"."channel",
	"foo"."col_name"
from
	(
	select
		'store' as "channel",
		'ss_customer_sk' as "col_name"
	from
		"store_sales"
union all
	select
		'web' as "channel",
		'ws_ship_hdemo_sk' as "col_name"
	from
		"web_sales") as "foo"
group by
	"foo"."channel",
	"foo"."col_name"
order by
	"foo"."channel" asc nulls last,
	"foo"."col_name" asc nulls last

@sgrebnov sgrebnov self-assigned this Oct 10, 2024
@sgrebnov sgrebnov merged commit 75a953f into spiceai-42 Oct 11, 2024
@sgrebnov sgrebnov deleted the sgrebnov/improve-union-unparsing branch October 11, 2024 15:04
sgrebnov added a commit that referenced this pull request Oct 15, 2024
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