Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1 | /* |
| 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 | /* |
| 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 database tpch if exists; |
| 27 | create database tpch; |
| 28 | |
| 29 | use tpch; |
| 30 | |
| 31 | |
| 32 | create type tpch.OrderType as |
| 33 | closed { |
| 34 | o_orderkey : int32, |
| 35 | o_custkey : int32, |
| 36 | o_orderstatus : string, |
| 37 | o_totalprice : double, |
| 38 | o_orderdate : string, |
| 39 | o_orderpriority : string, |
| 40 | o_clerk : string, |
| 41 | o_shippriority : int32, |
| 42 | o_comment : string |
| 43 | } |
| 44 | |
| 45 | create type tpch.CustomerType as |
| 46 | closed { |
| 47 | c_custkey : int32, |
| 48 | c_name : string, |
| 49 | c_address : string, |
| 50 | c_nationkey : int32, |
| 51 | c_phone : string, |
| 52 | c_acctbal : double, |
| 53 | c_mktsegment : string, |
| 54 | c_comment : string |
| 55 | } |
| 56 | |
| 57 | create type tpch.SupplierType as |
| 58 | closed { |
| 59 | s_suppkey : int32, |
| 60 | s_name : string, |
| 61 | s_address : string, |
| 62 | s_nationkey : int32, |
| 63 | s_phone : string, |
| 64 | s_acctbal : double, |
| 65 | s_comment : string |
| 66 | } |
| 67 | |
| 68 | create type tpch.NationType as |
| 69 | closed { |
| 70 | n_nationkey : int32, |
| 71 | n_name : string, |
| 72 | n_regionkey : int32, |
| 73 | n_comment : string |
| 74 | } |
| 75 | |
| 76 | create type tpch.RegionType as |
| 77 | closed { |
| 78 | r_regionkey : int32, |
| 79 | r_name : string, |
| 80 | r_comment : string |
| 81 | } |
| 82 | |
| 83 | create table Orders(OrderType) primary key o_orderkey; |
| 84 | |
| 85 | create table Supplier(SupplierType) primary key s_suppkey; |
| 86 | |
| 87 | create table Region(RegionType) primary key r_regionkey; |
| 88 | |
| 89 | create table Nation(NationType) primary key n_nationkey; |
| 90 | |
| 91 | create table Customer(CustomerType) primary key c_custkey; |
| 92 | |
| 93 | create table SelectedNation(NationType) primary key n_nationkey; |
| 94 | |
| 95 | with t as ( |
| 96 | select element {'n_nationkey':nation.n_nationkey,'n_name':nation.n_name} |
| 97 | from Nation as nation, |
| 98 | SelectedNation as sn |
| 99 | where (nation.n_nationkey = sn.n_nationkey) |
| 100 | ), |
| 101 | X as ( |
| 102 | select element {'nation_key':nation_key,'order_date':orderdate,'sum_price':sum} |
| 103 | from t as n, |
| 104 | Customer as customer, |
| 105 | Orders as orders |
| 106 | where ((orders.o_custkey = customer.c_custkey) and (customer.c_nationkey = n.n_nationkey)) |
| 107 | group by orders.o_orderdate as orderdate,n.n_nationkey as nation_key |
| 108 | with sum as tpch.sum(( |
| 109 | select element o.o_totalprice |
| 110 | from orders as o |
| 111 | )) |
| 112 | ) |
| 113 | select element {'nation_key':nation_key,'sum_price':( |
| 114 | select element {'orderdate':y.order_date,'sum_price':y.sum_price} |
| 115 | from x as y |
| 116 | order by y.sum_price desc |
| 117 | limit 3 |
| 118 | )} |
| 119 | from X as x |
| 120 | group by x.nation_key as nation_key |
| 121 | ; |