Skip to content

Commit

Permalink
Last 25 queries of TPC-DS (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius authored Dec 22, 2023
1 parent d56b8b1 commit abb887b
Show file tree
Hide file tree
Showing 24 changed files with 1,102 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ydb/library/benchmarks/queries/tpcds/yql/q76.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% include 'header.sql.jinja' %}

-- NB: Subquerys
-- start query 1 in stream 0 using template query76.tpl and seed 2031708268
select channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM (
SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price
FROM {{store_sales}} as store_sales
cross join {{item}} as item
cross join {{date_dim}} as date_dim
WHERE ss_customer_sk IS NULL
AND ss_sold_date_sk=d_date_sk
AND ss_item_sk=i_item_sk
UNION ALL
SELECT 'web' as channel, 'ws_ship_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price
FROM {{web_sales}} as web_sales
cross join {{item}} as item
cross join {{date_dim}} as date_dim
WHERE ws_ship_addr_sk IS NULL
AND ws_sold_date_sk=d_date_sk
AND ws_item_sk=i_item_sk
UNION ALL
SELECT 'catalog' as channel, 'cs_ship_mode_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price
FROM {{catalog_sales}} as catalog_sales
cross join {{item}} as item
cross join {{date_dim}} as date_dim
WHERE cs_ship_mode_sk IS NULL
AND cs_sold_date_sk=d_date_sk
AND cs_item_sk=i_item_sk) foo
GROUP BY channel, col_name, d_year, d_qoy, i_category
ORDER BY channel, col_name, d_year, d_qoy, i_category
limit 100;

-- end query 1 in stream 0 using template query76.tpl
111 changes: 111 additions & 0 deletions ydb/library/benchmarks/queries/tpcds/yql/q77.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{% include 'header.sql.jinja' %}

-- NB: Subquerys
$ss =
(select store.s_store_sk s_store_sk,
sum(ss_ext_sales_price) as sales,
sum(ss_net_profit) as profit
from {{store_sales}} as store_sales cross join
{{date_dim}} as date_dim cross join
{{store}} as store
where ss_sold_date_sk = d_date_sk
and cast(d_date as date) between cast('2000-08-16' as date)
and (cast('2000-08-16' as date) + DateTime::IntervalFromDays(30))
and ss_store_sk = s_store_sk
group by store.s_store_sk);

$sr =
(select store.s_store_sk s_store_sk,
sum(sr_return_amt) as returns,
sum(sr_net_loss) as profit_loss
from {{store_returns}} as store_returns cross join
{{date_dim}} as date_dim cross join
{{store}} as store
where sr_returned_date_sk = d_date_sk
and cast(d_date as date) between cast('2000-08-16' as date)
and (cast('2000-08-16' as date) + DateTime::IntervalFromDays(30))
and sr_store_sk = s_store_sk
group by store.s_store_sk);
$cs =
(select catalog_sales.cs_call_center_sk cs_call_center_sk,
sum(cs_ext_sales_price) as sales,
sum(cs_net_profit) as profit
from {{catalog_sales}} as catalog_sales cross join
{{date_dim}} as date_dim
where cs_sold_date_sk = d_date_sk
and cast(d_date as date) between cast('2000-08-16' as date)
and (cast('2000-08-16' as date) + DateTime::IntervalFromDays(30))
group by catalog_sales.cs_call_center_sk
);
$cr =
(select catalog_returns.cr_call_center_sk cr_call_center_sk,
sum(cr_return_amount) as returns,
sum(cr_net_loss) as profit_loss
from {{catalog_returns}} as catalog_returns cross join
{{date_dim}} as date_dim
where cr_returned_date_sk = d_date_sk
and cast(d_date as date) between cast('2000-08-16' as date)
and (cast('2000-08-16' as date) + DateTime::IntervalFromDays(30))
group by catalog_returns.cr_call_center_sk
);
$ws =
( select web_page.wp_web_page_sk wp_web_page_sk,
sum(ws_ext_sales_price) as sales,
sum(ws_net_profit) as profit
from {{web_sales}} as web_sales cross join
{{date_dim}} as date_dim cross join
{{web_page}} as web_page
where ws_sold_date_sk = d_date_sk
and cast(d_date as date) between cast('2000-08-16' as date)
and (cast('2000-08-16' as date) + DateTime::IntervalFromDays(30))
and ws_web_page_sk = wp_web_page_sk
group by web_page.wp_web_page_sk);
$wr =
(select web_page.wp_web_page_sk wp_web_page_sk,
sum(wr_return_amt) as returns,
sum(wr_net_loss) as profit_loss
from {{web_returns}} as web_returns cross join
{{date_dim}} as date_dim cross join
{{web_page}} as web_page
where wr_returned_date_sk = d_date_sk
and cast(d_date as date) between cast('2000-08-16' as date)
and (cast('2000-08-16' as date) + DateTime::IntervalFromDays(30))
and wr_web_page_sk = wp_web_page_sk
group by web_page.wp_web_page_sk);
-- start query 1 in stream 0 using template query77.tpl and seed 1819994127
select channel
, id
, sum(sales) as sales
, sum(returns) as returns
, sum(profit) as profit
from
(select 'store channel' as channel
, ss.s_store_sk as id
, sales
, coalesce(returns, 0) as returns
, (profit - coalesce(profit_loss,0)) as profit
from $ss ss left join $sr sr
on ss.s_store_sk = sr.s_store_sk
union all
select 'catalog channel' as channel
, cs_call_center_sk as id
, sales
, returns
, (profit - profit_loss) as profit
from $cs cs
cross join $cr cr
union all
select 'web channel' as channel
, ws.wp_web_page_sk as id
, sales
, coalesce(returns, 0) returns
, (profit - coalesce(profit_loss,0)) as profit
from $ws ws left join $wr wr
on ws.wp_web_page_sk = wr.wp_web_page_sk
) x
group by rollup (channel, id)
order by channel
,id
limit 100;

-- end query 1 in stream 0 using template query77.tpl
61 changes: 61 additions & 0 deletions ydb/library/benchmarks/queries/tpcds/yql/q78.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% include 'header.sql.jinja' %}

-- NB: Subquerys
$ws =
(select date_dim.d_year AS ws_sold_year, web_sales.ws_item_sk ws_item_sk,
web_sales.ws_bill_customer_sk ws_customer_sk,
sum(ws_quantity) ws_qty,
sum(ws_wholesale_cost) ws_wc,
sum(ws_sales_price) ws_sp
from {{web_sales}} as web_sales
left join {{web_returns}} as web_returns on web_returns.wr_order_number=web_sales.ws_order_number and web_sales.ws_item_sk=web_returns.wr_item_sk
join {{date_dim}} as date_dim on web_sales.ws_sold_date_sk = date_dim.d_date_sk
where wr_order_number is null
group by date_dim.d_year, web_sales.ws_item_sk, web_sales.ws_bill_customer_sk
);
$cs =
(select date_dim.d_year AS cs_sold_year, catalog_sales.cs_item_sk cs_item_sk,
catalog_sales.cs_bill_customer_sk cs_customer_sk,
sum(cs_quantity) cs_qty,
sum(cs_wholesale_cost) cs_wc,
sum(cs_sales_price) cs_sp
from {{catalog_sales}} as catalog_sales
left join {{catalog_returns}} as catalog_returns on catalog_returns.cr_order_number=catalog_sales.cs_order_number and catalog_sales.cs_item_sk=catalog_returns.cr_item_sk
join {{date_dim}} as date_dim on catalog_sales.cs_sold_date_sk = date_dim.d_date_sk
where cr_order_number is null
group by date_dim.d_year, catalog_sales.cs_item_sk, catalog_sales.cs_bill_customer_sk
);
$ss=
(select date_dim.d_year AS ss_sold_year, store_sales.ss_item_sk ss_item_sk,
store_sales.ss_customer_sk ss_customer_sk,
sum(ss_quantity) ss_qty,
sum(ss_wholesale_cost) ss_wc,
sum(ss_sales_price) ss_sp
from {{store_sales}} as store_sales
left join {{store_returns}} as store_returns on store_returns.sr_ticket_number=store_sales.ss_ticket_number and store_sales.ss_item_sk=store_returns.sr_item_sk
join {{date_dim}} as date_dim on store_sales.ss_sold_date_sk = date_dim.d_date_sk
where sr_ticket_number is null
group by date_dim.d_year, store_sales.ss_item_sk, store_sales.ss_customer_sk
);
-- start query 1 in stream 0 using template query78.tpl and seed 1819994127
select
ss_customer_sk,
Math::Round(cast(ss_qty as double)/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),-2) ratio,
ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price,
coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty,
coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost,
coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price
from $ss ss
left join $ws ws on (ws.ws_sold_year=ss.ss_sold_year and ws.ws_item_sk=ss.ss_item_sk and ws.ws_customer_sk=ss.ss_customer_sk)
left join $cs cs on (cs.cs_sold_year=ss.ss_sold_year and cs.cs_item_sk=ss.ss_item_sk and cs.cs_customer_sk=ss.ss_customer_sk)
where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001
order by
ss_customer_sk,
store_qty desc, store_wholesale_cost desc, store_sales_price desc,
other_chan_qty,
other_chan_wholesale_cost,
other_chan_sales_price,
ratio
limit 100;

-- end query 1 in stream 0 using template query78.tpl
29 changes: 29 additions & 0 deletions ydb/library/benchmarks/queries/tpcds/yql/q79.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% include 'header.sql.jinja' %}

-- NB: Subquerys
-- start query 1 in stream 0 using template query79.tpl and seed 2031708268
select
c_last_name,c_first_name,substring(cast(s_city as string),1,30) bla,ss_ticket_number,amt,profit
from
(select store_sales.ss_ticket_number ss_ticket_number
,store_sales.ss_customer_sk ss_customer_sk
,store.s_city s_city
,sum(ss_coupon_amt) amt
,sum(ss_net_profit) profit
from {{store_sales}} as store_sales
cross join {{date_dim}} as date_dim
cross join {{store}} as store
cross join {{household_demographics}} as household_demographics
where store_sales.ss_sold_date_sk = date_dim.d_date_sk
and store_sales.ss_store_sk = store.s_store_sk
and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 3)
and date_dim.d_dow = 1
and date_dim.d_year in (1998,1998+1,1998+2)
and store.s_number_employees between 200 and 295
group by store_sales.ss_ticket_number,store_sales.ss_customer_sk,store_sales.ss_addr_sk,store.s_city) ms cross join {{customer}} as customer
where ss_customer_sk = c_customer_sk
order by c_last_name,c_first_name,bla, profit
limit 100;

-- end query 1 in stream 0 using template query79.tpl
100 changes: 100 additions & 0 deletions ydb/library/benchmarks/queries/tpcds/yql/q80.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{% include 'header.sql.jinja' %}

-- NB: Subquerys
$ssr =
(select store.s_store_id as store_id,
sum(ss_ext_sales_price) as sales,
sum(coalesce(sr_return_amt, 0)) as returns,
sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit
from {{store_sales}} as store_sales
left join {{store_returns}} as store_returns on
(store_sales.ss_item_sk = store_returns.sr_item_sk and store_sales.ss_ticket_number = store_returns.sr_ticket_number) cross join
{{date_dim}} as date_dim cross join
{{store}} as store cross join
{{item}} as item cross join
{{promotion}} as promotion
where ss_sold_date_sk = d_date_sk
and cast(d_date as date) between cast('2002-08-06' as date)
and (cast('2002-08-06' as date) + DateTime::IntervalFromDays(30))
and ss_store_sk = s_store_sk
and ss_item_sk = i_item_sk
and i_current_price > 50
and ss_promo_sk = p_promo_sk
and p_channel_tv = 'N'
group by store.s_store_id);
$csr=
(select catalog_page.cp_catalog_page_id as catalog_page_id,
sum(cs_ext_sales_price) as sales,
sum(coalesce(cr_return_amount, 0)) as returns,
sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit
from {{catalog_sales}} as catalog_sales left join {{catalog_returns}} as catalog_returns on
(catalog_sales.cs_item_sk = catalog_returns.cr_item_sk and catalog_sales.cs_order_number = catalog_returns.cr_order_number) cross join
{{date_dim}} as date_dim cross join
{{catalog_page}} as catalog_page cross join
{{item}} as item cross join
{{promotion}} as promotion
where cs_sold_date_sk = d_date_sk
and cast(d_date as date) between cast('2002-08-06' as date)
and (cast('2002-08-06' as date) + DateTime::IntervalFromDays(30))
and cs_catalog_page_sk = cp_catalog_page_sk
and cs_item_sk = i_item_sk
and i_current_price > 50
and cs_promo_sk = p_promo_sk
and p_channel_tv = 'N'
group by catalog_page.cp_catalog_page_id)
;
$wsr =
(select web_site.web_site_id web_site_id,
sum(ws_ext_sales_price) as sales,
sum(coalesce(wr_return_amt, 0)) as returns,
sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit
from {{web_sales}} as web_sales
left outer join {{web_returns}} as web_returns on
(web_sales.ws_item_sk = web_returns.wr_item_sk and web_sales.ws_order_number = web_returns.wr_order_number) cross join
{{date_dim}} as date_dim cross join
{{web_site}} as web_site cross join
{{item}} as item cross join
{{promotion}} as promotion
where ws_sold_date_sk = d_date_sk
and cast(d_date as date) between cast('2002-08-06' as date)
and (cast('2002-08-06' as date) + DateTime::IntervalFromDays(30))
and ws_web_site_sk = web_site_sk
and ws_item_sk = i_item_sk
and i_current_price > 50
and ws_promo_sk = p_promo_sk
and p_channel_tv = 'N'
group by web_site.web_site_id);
-- start query 1 in stream 0 using template query80.tpl and seed 1819994127
select channel
, id
, sum(sales) as sales
, sum(returns) as returns
, sum(profit) as profit
from
(select 'store channel' as channel
, 'store' || store_id as id
, sales
, returns
, profit
from $ssr ssr
union all
select 'catalog channel' as channel
, 'catalog_page' || catalog_page_id as id
, sales
, returns
, profit
from $csr csr
union all
select 'web channel' as channel
, 'web_site' || web_site_id as id
, sales
, returns
, profit
from $wsr wsr
) x
group by rollup (channel, id)
order by channel
,id
limit 100;

-- end query 1 in stream 0 using template query80.tpl
34 changes: 34 additions & 0 deletions ydb/library/benchmarks/queries/tpcds/yql/q81.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% include 'header.sql.jinja' %}

-- NB: Subquerys
$customer_total_return =
(select catalog_returns.cr_returning_customer_sk as ctr_customer_sk
,customer_address.ca_state as ctr_state,
sum(cr_return_amt_inc_tax) as ctr_total_return
from {{catalog_returns}} as catalog_returns
cross join {{date_dim}} as date_dim
cross join {{customer_address}} as customer_address
where cr_returned_date_sk = d_date_sk
and d_year =1998
and cr_returning_addr_sk = ca_address_sk
group by catalog_returns.cr_returning_customer_sk
,customer_address.ca_state );
$avg_ctr_total_return = (select ctr_state, avg(ctr_total_return) as ctr_total_return from $customer_total_return group by ctr_state);
-- start query 1 in stream 0 using template query81.tpl and seed 1819994127
select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name
,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset
,ca_location_type,ctr1.ctr_total_return
from $customer_total_return ctr1
join $avg_ctr_total_return ctr2 on (ctr1.ctr_state = ctr2.ctr_state)
cross join {{customer_address}} as customer_address
cross join {{customer}} as customer
where ctr1.ctr_total_return > ctr2.ctr_total_return*1.2
and ca_address_sk = c_current_addr_sk
and ca_state = 'TX'
and ctr1.ctr_customer_sk = c_customer_sk
order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name
,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset
,ca_location_type,ctr1.ctr_total_return
limit 100;

-- end query 1 in stream 0 using template query81.tpl
23 changes: 23 additions & 0 deletions ydb/library/benchmarks/queries/tpcds/yql/q82.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% include 'header.sql.jinja' %}

-- NB: Subquerys
-- start query 1 in stream 0 using template query82.tpl and seed 55585014
select item.i_item_id
,item.i_item_desc
,item.i_current_price
from {{item}} as item
cross join {{inventory}} as inventory
cross join {{date_dim}} as date_dim
cross join {{store_sales}} as store_sales
where i_current_price between 49 and 49+30
and inv_item_sk = i_item_sk
and d_date_sk=inv_date_sk
and cast(d_date as date) between cast('2001-01-28' as date) and (cast('2001-01-28' as date) + DateTime::IntervalFromDays(60))
and i_manufact_id in (80,675,292,17)
and inv_quantity_on_hand between 100 and 500
and ss_item_sk = i_item_sk
group by item.i_item_id,item.i_item_desc,item.i_current_price
order by item.i_item_id
limit 100;

-- end query 1 in stream 0 using template query82.tpl
Loading

0 comments on commit abb887b

Please sign in to comment.