buyingyi | bd90411 | 2014-10-27 18:41:43 -0700 | [diff] [blame] | 1 | /* |
Ian Maxon | 857dc13 | 2015-09-25 17:13:19 -0700 | [diff] [blame^] | 2 | * 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 | /* |
buyingyi | bd90411 | 2014-10-27 18:41:43 -0700 | [diff] [blame] | 20 | * 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 | |
| 26 | drop dataverse tpch if exists; |
| 27 | create dataverse tpch; |
| 28 | |
| 29 | use dataverse tpch; |
| 30 | |
| 31 | create 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 | |
| 43 | create 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 | |
| 54 | create 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 | |
| 64 | create type NationType as closed { |
| 65 | n_nationkey: int32, |
| 66 | n_name: string, |
| 67 | n_regionkey: int32, |
| 68 | n_comment: string |
| 69 | } |
| 70 | |
| 71 | create type RegionType as closed { |
| 72 | r_regionkey: int32, |
| 73 | r_name: string, |
| 74 | r_comment: string |
| 75 | } |
| 76 | |
| 77 | create dataset Orders(OrderType) |
| 78 | primary key o_orderkey; |
| 79 | create dataset Supplier(SupplierType) |
| 80 | primary key s_suppkey; |
| 81 | create dataset Region(RegionType) |
| 82 | primary key r_regionkey; |
| 83 | create dataset Nation(NationType) |
| 84 | primary key n_nationkey; |
| 85 | create dataset Customer(CustomerType) |
| 86 | primary key c_custkey; |
| 87 | create dataset SelectedNation(NationType) |
| 88 | primary key n_nationkey; |
| 89 | |
| 90 | let $t := for $nation in dataset Nation |
| 91 | for $sn in dataset SelectedNation |
| 92 | where $nation.n_nationkey = $sn.n_nationkey /*+ indexnl */ |
| 93 | return { |
| 94 | "n_nationkey": $nation.n_nationkey, |
| 95 | "n_name": $nation.n_name |
| 96 | } |
| 97 | |
| 98 | let $X := ( |
| 99 | for $n in $t |
| 100 | for $customer in dataset Customer |
| 101 | for $order in dataset Orders |
| 102 | where $order.o_custkey = $customer.c_custkey |
| 103 | and $customer.c_nationkey = $n.n_nationkey |
| 104 | group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey with $order |
| 105 | let $sum := sum(for $o in $order return $o.o_totalprice) |
| 106 | return { |
| 107 | "nation_key": $nation_key, |
| 108 | "order_date": $orderdate, |
| 109 | "sum_price": $sum |
| 110 | }) |
| 111 | |
| 112 | for $x in $X |
| 113 | group by $nation_key := $x.nation_key with $x |
| 114 | return { |
| 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 | } |