blob: b2e4121e86fe47fa833f6be9f8b045f434b33c81 [file] [log] [blame]
Yingyi Bu391f09e2015-10-29 13:49:39 -07001/*
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 issue810
21 * https://code.google.com/p/asterixdb/issues/detail?id=810
22 * Expected Res : SUCCESS
23 * Date : 24th Nov. 2014
24 */
25
26drop database tpch if exists;
27create database tpch;
28
29use tpch;
30
31
32create 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 : double,
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
52create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
53
54select element {'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'count_cheaps':tpch.count(cheaps),'avg_expensive_discounts':tpch.avg(expensives),'sum_disc_prices':tpch.sum(disc_prices),'total_charges':tpch.sum(charges)}
55from LineItem as l
56where (l.l_shipdate <= '1998-09-02')
57/* +hash */
58group by l.l_returnflag as l_returnflag,l.l_linestatus as l_linestatus
59with expensives as (
60 select element i.l_discount
61 from l as i
62 where (i.l_discount <= 0.05)
63 ),
64 cheaps as (
65 select element i
66 from l as i
67 where (i.l_discount > 0.05)
68 ),
69 charges as (
70 select element (i.l_extendedprice * (1 - i.l_discount) * (1 + i.l_tax))
71 from l as i
72 ),
73 disc_prices as (
74 select element (i.l_extendedprice * (1 - i.l_discount))
75 from l as i
76 )
77order by l_returnflag,l_linestatus
78;