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 issue562 |
| 21 | * https://code.google.com/p/asterixdb/issues/detail?id=562 |
| 22 | * Expected Res : SUCCESS |
| 23 | * Date : 15th Jan. 2015 |
| 24 | */ |
| 25 | |
| 26 | drop database tpch if exists; |
| 27 | create database tpch; |
| 28 | |
| 29 | use tpch; |
| 30 | |
| 31 | |
| 32 | create type tpch.LineItemType as |
| 33 | closed { |
| 34 | l_orderkey : int32, |
| 35 | l_partkey : int32, |
| 36 | l_suppkey : int32, |
| 37 | l_linenumber : int32, |
| 38 | l_quantity : int32, |
| 39 | l_extendedprice : double, |
| 40 | l_discount : double, |
| 41 | l_tax : double, |
| 42 | l_returnflag : string, |
| 43 | l_linestatus : string, |
| 44 | l_shipdate : string, |
| 45 | l_commitdate : string, |
| 46 | l_receiptdate : string, |
| 47 | l_shipinstruct : string, |
| 48 | l_shipmode : string, |
| 49 | l_comment : string |
| 50 | } |
| 51 | |
| 52 | create type tpch.OrderType as |
| 53 | closed { |
| 54 | o_orderkey : int32, |
| 55 | o_custkey : int32, |
| 56 | o_orderstatus : string, |
| 57 | o_totalprice : double, |
| 58 | o_orderdate : string, |
| 59 | o_orderpriority : string, |
| 60 | o_clerk : string, |
| 61 | o_shippriority : int32, |
| 62 | o_comment : string |
| 63 | } |
| 64 | |
| 65 | create type tpch.CustomerType as |
| 66 | closed { |
| 67 | c_custkey : int32, |
| 68 | c_name : string, |
| 69 | c_address : string, |
| 70 | c_nationkey : int32, |
| 71 | c_phone : string, |
| 72 | c_acctbal : double, |
| 73 | c_mktsegment : string, |
| 74 | c_comment : string |
| 75 | } |
| 76 | |
| 77 | create table Orders(OrderType) primary key o_orderkey; |
| 78 | |
| 79 | create table Customer(CustomerType) primary key c_custkey; |
| 80 | |
| 81 | declare function q22_customer_tmp() { |
| 82 | ( |
| 83 | select element {'c_acctbal':c.c_acctbal,'c_custkey':c.c_custkey,'cntrycode':phone_substr} |
| 84 | from Customer as c |
| 85 | with phone_substr as tpch.substring(c.c_phone,1,2) |
| 86 | where ((phone_substr = '13') or (phone_substr = '31') or (phone_substr = '23') or (phone_substr = '29') or (phone_substr = '30') or (phone_substr = '18') or (phone_substr = '17')) |
| 87 | ) |
| 88 | }; |
| 89 | with avg as tpch.avg(( |
| 90 | select element c.c_acctbal |
| 91 | from Customer as c |
| 92 | with phone_substr as tpch.substring(c.c_phone,1,2) |
| 93 | where ((c.c_acctbal > 0.0) and ((phone_substr = '13') or (phone_substr = '31') or (phone_substr = '23') or (phone_substr = '29') or (phone_substr = '30') or (phone_substr = '18') or (phone_substr = '17'))) |
| 94 | )) |
| 95 | select element {'cntrycode':cntrycode,'numcust':tpch.count(ct),'totacctbal':tpch.sum(( |
| 96 | select element i.c_acctbal |
| 97 | from ct as i |
| 98 | ))} |
| 99 | from tpch.q22_customer_tmp() as ct |
| 100 | where (tpch.count(( |
| 101 | select element o |
| 102 | from Orders as o |
| 103 | where (ct.c_custkey = o.o_custkey) |
| 104 | )) = 0) |
| 105 | group by ct.cntrycode as cntrycode |
| 106 | order by cntrycode |
| 107 | ; |