Skip to content

Commit 67afd6e

Browse files
authored
First 25 queries of TPC-DS (#632)
1 parent 5167ea1 commit 67afd6e

File tree

25 files changed

+1550
-0
lines changed

25 files changed

+1550
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
-- NB: Used YQL's named expressions instead of ANSI SQL's "with" statement.
5+
$customer_total_return =
6+
-- NB: Must use correlation names (table names) in group by. And then everywhere else...
7+
(select a.sr_customer_sk as ctr_customer_sk
8+
,a.sr_store_sk as ctr_store_sk
9+
-- NB: renamed "SR_FEE" -> "sr_fee"
10+
,sum(a.sr_fee) as ctr_total_return
11+
from {{store_returns}} as a cross join {{date_dim}} as b
12+
where sr_returned_date_sk = d_date_sk
13+
and d_year =2000
14+
group by a.sr_customer_sk
15+
,a.sr_store_sk);
16+
17+
$avg_total_returns = (
18+
select ctr_store_sk, avg(ctr_total_return)*1.2 as ctr_avg
19+
from $customer_total_return
20+
group by ctr_store_sk
21+
);
22+
23+
-- -- start query 1 in stream 0 using template query1.tpl and seed 2031708268
24+
select c_customer_id
25+
from $customer_total_return ctr1
26+
cross join {{store}}
27+
cross join {{customer}}
28+
-- NB: Rewrote inequality condition with explicit join
29+
join $avg_total_returns ctr2 on ctr1.ctr_store_sk = ctr2.ctr_store_sk
30+
where ctr_total_return > ctr_avg
31+
and s_store_sk = ctr1.ctr_store_sk
32+
and s_state = 'NM'
33+
and ctr_customer_sk = c_customer_sk
34+
order by c_customer_id
35+
limit 100;
36+
37+
-- -- end query 1 in stream 0 using template query1.tpl
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
$bla1 = (select DISTINCT ss_customer_sk
5+
from {{store_sales}} as store_sales
6+
cross join {{date_dim}} as date_dim
7+
where ss_sold_date_sk = d_date_sk and
8+
d_year = 2000 and
9+
d_moy between 3 and 3+3);
10+
$bla2 = (select DISTINCT customer_sk from ((select ws_bill_customer_sk customer_sk
11+
from {{web_sales}} as web_sales
12+
cross join {{date_dim}} as date_dim
13+
where ws_sold_date_sk = d_date_sk and
14+
d_year = 2000 and
15+
d_moy between 3 ANd 3+3)
16+
union all
17+
(select cs_ship_customer_sk customer_sk
18+
from {{catalog_sales}} as catalog_sales
19+
cross join {{date_dim}} as date_dim
20+
where
21+
cs_sold_date_sk = d_date_sk and
22+
d_year = 2000 and
23+
d_moy between 3 and 3+3)));
24+
25+
-- start query 1 in stream 0 using template query10.tpl and seed 797269820
26+
select
27+
customer_demographics.cd_gender,
28+
customer_demographics.cd_marital_status,
29+
customer_demographics.cd_education_status,
30+
count(*) cnt1,
31+
customer_demographics.cd_purchase_estimate,
32+
count(*) cnt2,
33+
customer_demographics.cd_credit_rating,
34+
count(*) cnt3,
35+
customer_demographics.cd_dep_count,
36+
count(*) cnt4,
37+
customer_demographics.cd_dep_employed_count,
38+
count(*) cnt5,
39+
customer_demographics.cd_dep_college_count,
40+
count(*) cnt6
41+
from
42+
{{customer}} c
43+
cross join {{customer_address}} ca
44+
cross join {{customer_demographics}} as customer_demographics
45+
left semi join $bla1 bla1 on (c.c_customer_sk = bla1.ss_customer_sk)
46+
left semi join $bla2 bla2 on (c.c_customer_sk = bla2.customer_sk)
47+
where
48+
c.c_current_addr_sk = ca.ca_address_sk and
49+
ca_county in ('Fillmore County','McPherson County','Bonneville County','Boone County','Brown County') and
50+
cd_demo_sk = c.c_current_cdemo_sk
51+
group by customer_demographics.cd_gender,
52+
customer_demographics.cd_marital_status,
53+
customer_demographics.cd_education_status,
54+
customer_demographics.cd_purchase_estimate,
55+
customer_demographics.cd_credit_rating,
56+
customer_demographics.cd_dep_count,
57+
customer_demographics.cd_dep_employed_count,
58+
customer_demographics.cd_dep_college_count
59+
order by customer_demographics.cd_gender,
60+
customer_demographics.cd_marital_status,
61+
customer_demographics.cd_education_status,
62+
customer_demographics.cd_purchase_estimate,
63+
customer_demographics.cd_credit_rating,
64+
customer_demographics.cd_dep_count,
65+
customer_demographics.cd_dep_employed_count,
66+
customer_demographics.cd_dep_college_count
67+
limit 100;
68+
69+
-- end query 1 in stream 0 using template query10.tpl
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
5+
-- start query 1 in stream 0 using template query11.tpl and seed 1819994127
6+
$year_total = (
7+
select customer.c_customer_id customer_id
8+
,customer.c_first_name customer_first_name
9+
,customer.c_last_name customer_last_name
10+
,customer.c_preferred_cust_flag customer_preferred_cust_flag
11+
,customer.c_birth_country customer_birth_country
12+
,customer.c_login customer_login
13+
,customer.c_email_address customer_email_address
14+
,date_dim.d_year dyear
15+
,sum(ss_ext_list_price-ss_ext_discount_amt) year_total
16+
,'s' sale_type
17+
from {{customer}} as customer
18+
cross join {{store_sales}} as store_sales
19+
cross join {{date_dim}} as date_dim
20+
where c_customer_sk = ss_customer_sk
21+
and ss_sold_date_sk = d_date_sk
22+
group by customer.c_customer_id
23+
,customer.c_first_name
24+
,customer.c_last_name
25+
,customer.c_preferred_cust_flag
26+
,customer.c_birth_country
27+
,customer.c_login
28+
,customer.c_email_address
29+
,date_dim.d_year
30+
union all
31+
select customer.c_customer_id customer_id
32+
,customer.c_first_name customer_first_name
33+
,customer.c_last_name customer_last_name
34+
,customer.c_preferred_cust_flag customer_preferred_cust_flag
35+
,customer.c_birth_country customer_birth_country
36+
,customer.c_login customer_login
37+
,customer.c_email_address customer_email_address
38+
,date_dim.d_year dyear
39+
,sum(ws_ext_list_price-ws_ext_discount_amt) year_total
40+
,'w' sale_type
41+
from {{customer}} as customer
42+
cross join {{web_sales}} as web_sales
43+
cross join {{date_dim}} as date_dim
44+
where c_customer_sk = ws_bill_customer_sk
45+
and ws_sold_date_sk = d_date_sk
46+
group by customer.c_customer_id
47+
,customer.c_first_name
48+
,customer.c_last_name
49+
,customer.c_preferred_cust_flag
50+
,customer.c_birth_country
51+
,customer.c_login
52+
,customer.c_email_address
53+
,date_dim.d_year
54+
);
55+
56+
select
57+
t_s_secyear.customer_id
58+
,t_s_secyear.customer_first_name
59+
,t_s_secyear.customer_last_name
60+
,t_s_secyear.customer_birth_country
61+
from $year_total t_s_firstyear
62+
cross join $year_total t_s_secyear
63+
cross join $year_total t_w_firstyear
64+
cross join $year_total t_w_secyear
65+
where t_s_secyear.customer_id = t_s_firstyear.customer_id
66+
and t_s_firstyear.customer_id = t_w_secyear.customer_id
67+
and t_s_firstyear.customer_id = t_w_firstyear.customer_id
68+
and t_s_firstyear.sale_type = 's'
69+
and t_w_firstyear.sale_type = 'w'
70+
and t_s_secyear.sale_type = 's'
71+
and t_w_secyear.sale_type = 'w'
72+
and t_s_firstyear.dyear = 1999
73+
and t_s_secyear.dyear = 1999+1
74+
and t_w_firstyear.dyear = 1999
75+
and t_w_secyear.dyear = 1999+1
76+
and t_s_firstyear.year_total > 0
77+
and t_w_firstyear.year_total > 0
78+
and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end
79+
> case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end
80+
order by t_s_secyear.customer_id
81+
,t_s_secyear.customer_first_name
82+
,t_s_secyear.customer_last_name
83+
,t_s_secyear.customer_birth_country
84+
limit 100;
85+
86+
-- end query 1 in stream 0 using template query11.tpl
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
-- start query 1 in stream 0 using template query12.tpl and seed 345591136
5+
select item.i_item_id
6+
,item.i_item_desc
7+
,item.i_category
8+
,item.i_class
9+
,item.i_current_price
10+
,sum(web_sales.ws_ext_sales_price) as itemrevenue
11+
,sum(web_sales.ws_ext_sales_price)*100/sum(sum(web_sales.ws_ext_sales_price)) over
12+
(partition by item.i_class) as revenueratio
13+
from
14+
{{web_sales}} as web_sales
15+
cross join {{item}} as item
16+
cross join {{date_dim}} as date_dim
17+
where
18+
web_sales.ws_item_sk = item.i_item_sk
19+
and item.i_category in ('Electronics', 'Books', 'Women')
20+
and web_sales.ws_sold_date_sk = date_dim.d_date_sk
21+
and cast(date_dim.d_date as date) between cast('1998-01-06' as date)
22+
and (cast('1998-01-06' as date) + cast('P30D' as interval))
23+
group by
24+
item.i_item_id
25+
,item.i_item_desc
26+
,item.i_category
27+
,item.i_class
28+
,item.i_current_price
29+
order by
30+
item.i_category
31+
,item.i_class
32+
,item.i_item_id
33+
,item.i_item_desc
34+
,revenueratio
35+
limit 100;
36+
-- end query 1 in stream 0 using template query12.tpl
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
5+
-- start query 1 in stream 0 using template query13.tpl and seed 622697896
6+
select avg(ss_quantity)
7+
,avg(ss_ext_sales_price)
8+
,avg(ss_ext_wholesale_cost)
9+
,sum(ss_ext_wholesale_cost)
10+
from {{store_sales}} as store_sales
11+
cross join {{store}} as store
12+
cross join {{customer_demographics}} as customer_demographics
13+
cross join {{household_demographics}} as household_demographics
14+
cross join {{customer_address}} as customer_address
15+
cross join {{date_dim}} as date_dim
16+
where s_store_sk = ss_store_sk
17+
and ss_sold_date_sk = d_date_sk and d_year = 2001
18+
and((ss_hdemo_sk=hd_demo_sk
19+
and cd_demo_sk = ss_cdemo_sk
20+
and cd_marital_status = 'U'
21+
and cd_education_status = 'Secondary'
22+
and ss_sales_price between 100.00 and 150.00
23+
and hd_dep_count = 3
24+
)or
25+
(ss_hdemo_sk=hd_demo_sk
26+
and cd_demo_sk = ss_cdemo_sk
27+
and cd_marital_status = 'W'
28+
and cd_education_status = 'College'
29+
and ss_sales_price between 50.00 and 100.00
30+
and hd_dep_count = 1
31+
) or
32+
(ss_hdemo_sk=hd_demo_sk
33+
and cd_demo_sk = ss_cdemo_sk
34+
and cd_marital_status = 'D'
35+
and cd_education_status = 'Primary'
36+
and ss_sales_price between 150.00 and 200.00
37+
and hd_dep_count = 1
38+
))
39+
and((ss_addr_sk = ca_address_sk
40+
and ca_country = 'United States'
41+
and ca_state in ('TX', 'OK', 'MI')
42+
and ss_net_profit between 100 and 200
43+
) or
44+
(ss_addr_sk = ca_address_sk
45+
and ca_country = 'United States'
46+
and ca_state in ('WA', 'NC', 'OH')
47+
and ss_net_profit between 150 and 300
48+
) or
49+
(ss_addr_sk = ca_address_sk
50+
and ca_country = 'United States'
51+
and ca_state in ('MT', 'FL', 'GA')
52+
and ss_net_profit between 50 and 250
53+
))
54+
;
55+
56+
-- end query 1 in stream 0 using template query13.tpl

0 commit comments

Comments
 (0)