blob: 2f484b8c1781f90bc1e0f90b88349e0b4a3aad2f [file] [log] [blame]
/*
* 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.
*/
DROP DATAVERSE test IF EXISTS;
CREATE DATAVERSE test;
USE test;
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 EXTERNAL DATASET Customer(CustomerType) USING `localfs`
((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),
(`input-format`=`text-input-format`),(`format`=`delimited-text`),(`delimiter`=`|`));
CREATE EXTERNAL DATASET Orders(OrderType) USING `localfs`
((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),
(`input-format`=`text-input-format`),(`format`=`delimited-text`),(`delimiter`=`|`));
WITH q22_customer_tmp AS
(
SELECT c_acctbal, c_custkey, substring(c_phone,1,2) AS cntrycode
FROM Customer
)
,
avg AS (
SELECT ELEMENT AVG(c_acctbal)
FROM Customer
WHERE c_acctbal > 0.0
)[0]
SELECT cntrycode, count(ct) AS numcust, SUM(c_acctbal) AS totacctbal
FROM q22_customer_tmp AS ct
WHERE c_acctbal > avg
AND NOT EXISTS (SELECT * FROM Orders o WHERE o.o_custkey = ct.c_custkey)
GROUP BY cntrycode
ORDER BY cntrycode
;