buyingyi | a9a0202 | 2015-01-15 10:40:15 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Description : This test case is to verify the fix for issue562 |
| 3 | * https://code.google.com/p/asterixdb/issues/detail?id=562 |
| 4 | * Expected Res : SUCCESS |
| 5 | * Date : 15th Jan. 2015 |
| 6 | */ |
| 7 | |
| 8 | drop dataverse tpch if exists; |
| 9 | create dataverse tpch; |
| 10 | |
| 11 | use dataverse tpch; |
| 12 | |
| 13 | create type LineItemType as closed { |
| 14 | l_orderkey: int32, |
| 15 | l_partkey: int32, |
| 16 | l_suppkey: int32, |
| 17 | l_linenumber: int32, |
| 18 | l_quantity: int32, |
| 19 | l_extendedprice: double, |
| 20 | l_discount: double, |
| 21 | l_tax: double, |
| 22 | l_returnflag: string, |
| 23 | l_linestatus: string, |
| 24 | l_shipdate: string, |
| 25 | l_commitdate: string, |
| 26 | l_receiptdate: string, |
| 27 | l_shipinstruct: string, |
| 28 | l_shipmode: string, |
| 29 | l_comment: string |
| 30 | } |
| 31 | |
| 32 | create type OrderType as closed { |
| 33 | o_orderkey: int32, |
| 34 | o_custkey: int32, |
| 35 | o_orderstatus: string, |
| 36 | o_totalprice: double, |
| 37 | o_orderdate: string, |
| 38 | o_orderpriority: string, |
| 39 | o_clerk: string, |
| 40 | o_shippriority: int32, |
| 41 | o_comment: string |
| 42 | } |
| 43 | |
| 44 | create type CustomerType as closed { |
| 45 | c_custkey: int32, |
| 46 | c_name: string, |
| 47 | c_address: string, |
| 48 | c_nationkey: int32, |
| 49 | c_phone: string, |
| 50 | c_acctbal: double, |
| 51 | c_mktsegment: string, |
| 52 | c_comment: string |
| 53 | } |
| 54 | |
| 55 | create dataset Orders(OrderType) |
| 56 | primary key o_orderkey; |
| 57 | create dataset Customer(CustomerType) |
| 58 | primary key c_custkey; |
| 59 | |
| 60 | declare function q22_customer_tmp() { |
| 61 | for $c in dataset('Customer') |
| 62 | let $phone_substr := substring($c.c_phone, 1, 2) |
| 63 | where $phone_substr = '13' |
| 64 | or $phone_substr = '31' |
| 65 | or $phone_substr = '23' |
| 66 | or $phone_substr = '29' |
| 67 | or $phone_substr = '30' |
| 68 | or $phone_substr = '18' |
| 69 | or $phone_substr = '17' |
| 70 | return { |
| 71 | "c_acctbal": $c.c_acctbal, |
| 72 | "c_custkey": $c.c_custkey, |
| 73 | "cntrycode": $phone_substr |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | let $avg := avg( |
| 78 | for $c in dataset('Customer') |
| 79 | let $phone_substr := substring($c.c_phone, 1, 2) |
| 80 | where $c.c_acctbal > 0.00 |
| 81 | and ($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 $c.c_acctbal |
| 89 | ) |
| 90 | |
| 91 | for $ct in q22_customer_tmp() |
| 92 | where count(for $o in dataset('Orders') where $ct.c_custkey = $o.o_custkey return $o) = 0 |
| 93 | group by $cntrycode := $ct.cntrycode with $ct |
| 94 | order by $cntrycode |
| 95 | return { |
| 96 | "cntrycode": $cntrycode, |
| 97 | "numcust": count($ct), |
| 98 | "totacctbal": sum(for $i in $ct return $i.c_acctbal) |
| 99 | } |