blob: 789cbe078683fcee63da2937cae7e1ed382d20f6 [file] [log] [blame]
buyingyia9a02022015-01-15 10:40:15 -08001/*
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/*
buyingyia9a02022015-01-15 10:40:15 -080020 * 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
26drop dataverse tpch if exists;
27create dataverse tpch;
28
29use dataverse tpch;
30
31create type LineItemType as closed {
32 l_orderkey: int32,
33 l_partkey: int32,
34 l_suppkey: int32,
35 l_linenumber: int32,
36 l_quantity: int32,
37 l_extendedprice: double,
38 l_discount: double,
39 l_tax: double,
40 l_returnflag: string,
41 l_linestatus: string,
42 l_shipdate: string,
43 l_commitdate: string,
44 l_receiptdate: string,
45 l_shipinstruct: string,
46 l_shipmode: string,
47 l_comment: string
48}
49
50create type OrderType as closed {
51 o_orderkey: int32,
52 o_custkey: int32,
53 o_orderstatus: string,
54 o_totalprice: double,
55 o_orderdate: string,
56 o_orderpriority: string,
57 o_clerk: string,
58 o_shippriority: int32,
59 o_comment: string
60}
61
62create type CustomerType as closed {
63 c_custkey: int32,
64 c_name: string,
65 c_address: string,
66 c_nationkey: int32,
67 c_phone: string,
68 c_acctbal: double,
69 c_mktsegment: string,
70 c_comment: string
71}
72
73create dataset Orders(OrderType)
74 primary key o_orderkey;
75create dataset Customer(CustomerType)
76 primary key c_custkey;
77
78declare function q22_customer_tmp() {
79 for $c in dataset('Customer')
80 let $phone_substr := substring($c.c_phone, 1, 2)
81 where $phone_substr = '13'
82 or $phone_substr = '31'
83 or $phone_substr = '23'
84 or $phone_substr = '29'
85 or $phone_substr = '30'
86 or $phone_substr = '18'
87 or $phone_substr = '17'
88 return {
89 "c_acctbal": $c.c_acctbal,
90 "c_custkey": $c.c_custkey,
91 "cntrycode": $phone_substr
92 }
93}
94
95let $avg := avg(
96 for $c in dataset('Customer')
97 let $phone_substr := substring($c.c_phone, 1, 2)
98 where $c.c_acctbal > 0.00
99 and ($phone_substr = '13'
100 or $phone_substr = '31'
101 or $phone_substr = '23'
102 or $phone_substr = '29'
103 or $phone_substr = '30'
104 or $phone_substr = '18'
105 or $phone_substr = '17')
106 return $c.c_acctbal
107)
108
109for $ct in q22_customer_tmp()
110where count(for $o in dataset('Orders') where $ct.c_custkey = $o.o_custkey return $o) = 0
111group by $cntrycode := $ct.cntrycode with $ct
112order by $cntrycode
113return {
114 "cntrycode": $cntrycode,
115 "numcust": count($ct),
116 "totacctbal": sum(for $i in $ct return $i.c_acctbal)
Ian Maxon857dc132015-09-25 17:13:19 -0700117}