blob: 89a95310f81fd05409e1c4f52f587b6b749f0b75 [file] [log] [blame]
buyingyibd904112014-10-27 18:41:43 -07001/*
2 * Description : This test case is to verify the fix for issue785
3 * https://code.google.com/p/asterixdb/issues/detail?id=785
4 * Expected Res : SUCCESS
5 * Date : 2nd Oct. 2014
6 */
7
8drop dataverse tpch if exists;
9create dataverse tpch;
10
11use dataverse tpch;
12
13create type OrderType as closed {
14 o_orderkey: int32,
15 o_custkey: int32,
16 o_orderstatus: string,
17 o_totalprice: double,
18 o_orderdate: string,
19 o_orderpriority: string,
20 o_clerk: string,
21 o_shippriority: int32,
22 o_comment: string
23}
24
25create type CustomerType as closed {
26 c_custkey: int32,
27 c_name: string,
28 c_address: string,
29 c_nationkey: int32,
30 c_phone: string,
31 c_acctbal: double,
32 c_mktsegment: string,
33 c_comment: string
34}
35
36create type SupplierType as closed {
37 s_suppkey: int32,
38 s_name: string,
39 s_address: string,
40 s_nationkey: int32,
41 s_phone: string,
42 s_acctbal: double,
43 s_comment: string
44}
45
46create type NationType as closed {
47 n_nationkey: int32,
48 n_name: string,
49 n_regionkey: int32,
50 n_comment: string
51}
52
53create type RegionType as closed {
54 r_regionkey: int32,
55 r_name: string,
56 r_comment: string
57}
58
59create dataset Orders(OrderType)
60 primary key o_orderkey;
61create dataset Supplier(SupplierType)
62 primary key s_suppkey;
63create dataset Region(RegionType)
64 primary key r_regionkey;
65create dataset Nation(NationType)
66 primary key n_nationkey;
67create dataset Customer(CustomerType)
68 primary key c_custkey;
69create dataset SelectedNation(NationType)
70 primary key n_nationkey;
71
72let $t := for $nation in dataset Nation
73for $sn in dataset SelectedNation
74where $nation.n_nationkey = $sn.n_nationkey /*+ indexnl */
75return {
76 "n_nationkey": $nation.n_nationkey,
77 "n_name": $nation.n_name
78}
79
80let $X := (
81for $n in $t
82for $customer in dataset Customer
83for $order in dataset Orders
84where $order.o_custkey = $customer.c_custkey
85and $customer.c_nationkey = $n.n_nationkey
86group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey with $order
87let $sum := sum(for $o in $order return $o.o_totalprice)
88return {
89 "nation_key": $nation_key,
90 "order_date": $orderdate,
91 "sum_price": $sum
92})
93
94for $x in $X
95group by $nation_key := $x.nation_key with $x
96return {
97 "nation_key": $nation_key,
98 "sum_price": for $y in $x
99 order by $y.sum_price desc
100 limit 3
101 return {
102 "orderdate": $y.order_date,
103 "sum_price": $y.sum_price
104 }
105}