blob: 6df0d5acbf4d331afd0d7b0b86337efcc46d1da0 [file] [log] [blame]
buyingyibd904112014-10-27 18:41:43 -07001/*
Ian Maxon857dc132015-09-25 17:13:19 -07002 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19/*
buyingyibd904112014-10-27 18:41:43 -070020 * Description : This test case is to verify the fix for issue785
21 * https://code.google.com/p/asterixdb/issues/detail?id=785
22 * Expected Res : SUCCESS
23 * Date : 2nd Oct. 2014
24 */
25
26drop dataverse tpch if exists;
27create dataverse tpch;
28
29use dataverse tpch;
30
31create type OrderType as closed {
32 o_orderkey: int32,
33 o_custkey: int32,
34 o_orderstatus: string,
35 o_totalprice: double,
36 o_orderdate: string,
37 o_orderpriority: string,
38 o_clerk: string,
39 o_shippriority: int32,
40 o_comment: string
41}
42
43create type CustomerType as closed {
44 c_custkey: int32,
45 c_name: string,
46 c_address: string,
47 c_nationkey: int32,
48 c_phone: string,
49 c_acctbal: double,
50 c_mktsegment: string,
51 c_comment: string
52}
53
54create type SupplierType as closed {
55 s_suppkey: int32,
56 s_name: string,
57 s_address: string,
58 s_nationkey: int32,
59 s_phone: string,
60 s_acctbal: double,
61 s_comment: string
62}
63
64create type NationType as closed {
65 n_nationkey: int32,
66 n_name: string,
67 n_regionkey: int32,
68 n_comment: string
69}
70
71create type RegionType as closed {
72 r_regionkey: int32,
73 r_name: string,
74 r_comment: string
75}
76
77create dataset Orders(OrderType)
78 primary key o_orderkey;
79create dataset Supplier(SupplierType)
80 primary key s_suppkey;
81create dataset Region(RegionType)
82 primary key r_regionkey;
83create dataset Nation(NationType)
84 primary key n_nationkey;
85create dataset Customer(CustomerType)
86 primary key c_custkey;
87create dataset SelectedNation(NationType)
88 primary key n_nationkey;
89
90let $t := for $nation in dataset Nation
91for $sn in dataset SelectedNation
92where $nation.n_nationkey = $sn.n_nationkey /*+ indexnl */
93return {
94 "n_nationkey": $nation.n_nationkey,
95 "n_name": $nation.n_name
96}
97
98let $X := (
99for $n in $t
100for $customer in dataset Customer
101for $order in dataset Orders
102where $order.o_custkey = $customer.c_custkey
103and $customer.c_nationkey = $n.n_nationkey
104group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey with $order
105let $sum := sum(for $o in $order return $o.o_totalprice)
106return {
107 "nation_key": $nation_key,
108 "order_date": $orderdate,
109 "sum_price": $sum
110})
111
112for $x in $X
113group by $nation_key := $x.nation_key with $x
114return {
115 "nation_key": $nation_key,
116 "sum_price": for $y in $x
117 order by $y.sum_price desc
118 limit 3
119 return {
120 "orderdate": $y.order_date,
121 "sum_price": $y.sum_price
122 }
123}