buyingyi | bd90411 | 2014-10-27 18:41:43 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 8 | drop dataverse tpch if exists; |
| 9 | create dataverse tpch; |
| 10 | |
| 11 | use dataverse tpch; |
| 12 | |
| 13 | create 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 | |
| 25 | create 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 | |
| 36 | create 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 | |
| 46 | create type NationType as closed { |
| 47 | n_nationkey: int32, |
| 48 | n_name: string, |
| 49 | n_regionkey: int32, |
| 50 | n_comment: string |
| 51 | } |
| 52 | |
| 53 | create type RegionType as closed { |
| 54 | r_regionkey: int32, |
| 55 | r_name: string, |
| 56 | r_comment: string |
| 57 | } |
| 58 | |
| 59 | create dataset Orders(OrderType) |
| 60 | primary key o_orderkey; |
| 61 | create dataset Supplier(SupplierType) |
| 62 | primary key s_suppkey; |
| 63 | create dataset Region(RegionType) |
| 64 | primary key r_regionkey; |
| 65 | create dataset Nation(NationType) |
| 66 | primary key n_nationkey; |
| 67 | create dataset Customer(CustomerType) |
| 68 | primary key c_custkey; |
| 69 | create dataset SelectedNation(NationType) |
| 70 | primary key n_nationkey; |
| 71 | |
| 72 | let $t := for $nation in dataset Nation |
| 73 | for $sn in dataset SelectedNation |
| 74 | where $nation.n_nationkey = $sn.n_nationkey /*+ indexnl */ |
| 75 | return { |
| 76 | "n_nationkey": $nation.n_nationkey, |
| 77 | "n_name": $nation.n_name |
| 78 | } |
| 79 | |
| 80 | let $X := ( |
| 81 | for $n in $t |
| 82 | for $customer in dataset Customer |
| 83 | for $order in dataset Orders |
| 84 | where $order.o_custkey = $customer.c_custkey |
| 85 | and $customer.c_nationkey = $n.n_nationkey |
| 86 | group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey with $order |
| 87 | let $sum := sum(for $o in $order return $o.o_totalprice) |
| 88 | return { |
| 89 | "nation_key": $nation_key, |
| 90 | "order_date": $orderdate, |
| 91 | "sum_price": $sum |
| 92 | }) |
| 93 | |
| 94 | for $x in $X |
| 95 | group by $nation_key := $x.nation_key with $x |
| 96 | return { |
| 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 | } |