| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| /* |
| * Description : This test case is to verify the fix for issue562 |
| * https://code.google.com/p/asterixdb/issues/detail?id=562 |
| * Expected Res : SUCCESS |
| * Date : 15th Jan. 2015 |
| */ |
| |
| drop dataverse tpch if exists; |
| create dataverse tpch; |
| |
| use dataverse tpch; |
| |
| create type LineItemType as closed { |
| l_orderkey: int32, |
| l_partkey: int32, |
| l_suppkey: int32, |
| l_linenumber: int32, |
| l_quantity: int32, |
| l_extendedprice: double, |
| l_discount: double, |
| l_tax: double, |
| l_returnflag: string, |
| l_linestatus: string, |
| l_shipdate: string, |
| l_commitdate: string, |
| l_receiptdate: string, |
| l_shipinstruct: string, |
| l_shipmode: string, |
| l_comment: string |
| } |
| |
| create type OrderType as closed { |
| o_orderkey: int32, |
| o_custkey: int32, |
| o_orderstatus: string, |
| o_totalprice: double, |
| o_orderdate: string, |
| o_orderpriority: string, |
| o_clerk: string, |
| o_shippriority: int32, |
| o_comment: string |
| } |
| |
| create type CustomerType as closed { |
| c_custkey: int32, |
| c_name: string, |
| c_address: string, |
| c_nationkey: int32, |
| c_phone: string, |
| c_acctbal: double, |
| c_mktsegment: string, |
| c_comment: string |
| } |
| |
| create dataset Orders(OrderType) |
| primary key o_orderkey; |
| create dataset Customer(CustomerType) |
| primary key c_custkey; |
| |
| declare function q22_customer_tmp() { |
| for $c in dataset('Customer') |
| let $phone_substr := substring($c.c_phone, 1, 2) |
| 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' |
| return { |
| "c_acctbal": $c.c_acctbal, |
| "c_custkey": $c.c_custkey, |
| "cntrycode": $phone_substr |
| } |
| } |
| |
| let $avg := avg( |
| for $c in dataset('Customer') |
| let $phone_substr := substring($c.c_phone, 1, 2) |
| where $c.c_acctbal > 0.00 |
| 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') |
| return $c.c_acctbal |
| ) |
| |
| for $ct in q22_customer_tmp() |
| where count(for $o in dataset('Orders') where $ct.c_custkey = $o.o_custkey return $o) = 0 |
| group by $cntrycode := $ct.cntrycode with $ct |
| order by $cntrycode |
| return { |
| "cntrycode": $cntrycode, |
| "numcust": count($ct), |
| "totacctbal": sum(for $i in $ct return $i.c_acctbal) |
| } |