blob: 16fc8e45bfa6ce7f041e8d5cf19d4b7f191f4fe6 [file] [log] [blame]
Yingyi Bud5f0fc52014-06-09 13:49:23 -07001/*
2 * Description : This test case is to verify the fix for issue782
3 * https://code.google.com/p/asterixdb/issues/detail?id=782
4 * Expected Res : SUCCESS
5 * Date : 2nd Jun 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 type PartType as closed {
60 p_partkey: int32,
61 p_name: string,
62 p_mfgr: string,
63 p_brand: string,
64 p_type: string,
65 p_size: int32,
66 p_container: string,
67 p_retailprice: double,
68 p_comment: string
69}
70
71create type PartSuppType as closed {
72 ps_partkey: int32,
73 ps_suppkey: int32,
74 ps_availqty: int32,
75 ps_supplycost: double,
76 ps_comment: string
77}
78
79create dataset Orders(OrderType)
80 primary key o_orderkey;
81create dataset Supplier(SupplierType)
82 primary key s_suppkey;
83create dataset Region(RegionType)
84 primary key r_regionkey;
85create dataset Nation(NationType)
86 primary key n_nationkey;
87create dataset Part(PartType)
88 primary key p_partkey;
89create dataset Partsupp(PartSuppType)
90 primary key ps_partkey, ps_suppkey;
91create dataset Customer(CustomerType)
92 primary key c_custkey;
93create dataset SelectedNation(NationType)
94 primary key n_nationkey;
95
96
97
98for $nation in dataset Nation
99for $sn in dataset SelectedNation
100where $nation.n_nationkey = $sn.n_nationkey /*+ indexnl */
101return {
102 "nation_key": $nation.n_nationkey,
103 "name": $nation.n_name,
104 "aggregates": for $order in dataset Orders
105 for $customer in dataset Customer
106 where $order.o_custkey = $customer.c_custkey
107 and $customer.c_nationkey = $nation.n_nationkey
108 group by $orderdate := $order.o_orderdate with $order
109 let $sum := sum(for $o in $order return $o.o_totalprice)
110 order by $sum
111 limit 3
112 return {
113 "order_date": $orderdate,
114 "sum_price": $sum
115 }
116}