blob: 05b1c3602c49287bc683b92af0e859b8d8d53dd9 [file] [log] [blame]
Yingyi Bu8aa0b512016-03-15 17:46:00 -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
20drop dataverse tpch if exists;
21drop nodegroup group_test if exists;
22create dataverse tpch;
23
24use dataverse tpch;
25
26create type LineItemType as closed {
27 l_orderkey: int64,
28 l_partkey: int64,
29 l_suppkey: int64,
30 l_linenumber: int64,
31 l_quantity: int64,
32 l_extendedprice: double,
33 l_discount: double,
34 l_tax: double,
35 l_returnflag: string,
36 l_linestatus: string,
37 l_shipdate: string,
38 l_commitdate: string,
39 l_receiptdate: string,
40 l_shipinstruct: string,
41 l_shipmode: string,
42 l_comment: string
43}
44
45create type OrderType as closed {
46 o_orderkey: int64,
47 o_custkey: int64,
48 o_orderstatus: string,
49 o_totalprice: double,
50 o_orderdate: string,
51 o_orderpriority: string,
52 o_clerk: string,
53 o_shippriority: int64,
54 o_comment: string
55}
56
57create nodegroup group_test on
58 asterix_nc1;
59
60create dataset LineItem(LineItemType)
61 primary key l_orderkey, l_linenumber on group_test;
62create dataset Orders(OrderType)
63 primary key o_orderkey on group_test;
64
65create index lineitem_shipdateIx on LineItem (l_shipdate);
66create index lineitem_receiptdateIx on LineItem (l_receiptdate);
67create index lineitem_fk_orders on LineItem (l_orderkey);
68create index lineitem_fk_part on LineItem (l_partkey);
69create index lineitem_fk_supplier on LineItem (l_suppkey);
70create index orders_fk_customer on Orders (o_custkey);
71create index orders_orderdateIx on Orders (o_orderdate);
72
73declare function tmp()
74{
75 for $l in dataset('LineItem')
76 where $l.l_commitdate < $l.l_receiptdate
77 distinct by $l.l_orderkey
78 return { "o_orderkey": $l.l_orderkey }
79}
80
81for $o in dataset('Orders')
82for $t in tmp()
83where $o.o_orderkey = $t.o_orderkey and
84 $o.o_orderdate >= '1993-07-01' and $o.o_orderdate < '1993-10-01'
85group by $o_orderpriority := $o.o_orderpriority with $o
86order by $o_orderpriority
87return {
88 "order_priority": $o_orderpriority,
89 "count": count($o)
90}
91
92
93drop dataverse tpch if exists;
94drop nodegroup group_test if exists;