Yingyi Bu | 8aa0b51 | 2016-03-15 17:46:00 -0700 | [diff] [blame] | 1 | /* |
| 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 | drop dataverse tpch if exists; |
| 21 | drop nodegroup group_test if exists; |
| 22 | create dataverse tpch; |
| 23 | |
| 24 | use dataverse tpch; |
| 25 | |
| 26 | create 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 | |
| 45 | create 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 | |
| 57 | create nodegroup group_test on |
| 58 | asterix_nc1; |
| 59 | |
| 60 | create dataset LineItem(LineItemType) |
| 61 | primary key l_orderkey, l_linenumber on group_test; |
| 62 | create dataset Orders(OrderType) |
| 63 | primary key o_orderkey on group_test; |
| 64 | |
| 65 | create index lineitem_shipdateIx on LineItem (l_shipdate); |
| 66 | create index lineitem_receiptdateIx on LineItem (l_receiptdate); |
| 67 | create index lineitem_fk_orders on LineItem (l_orderkey); |
| 68 | create index lineitem_fk_part on LineItem (l_partkey); |
| 69 | create index lineitem_fk_supplier on LineItem (l_suppkey); |
| 70 | create index orders_fk_customer on Orders (o_custkey); |
| 71 | create index orders_orderdateIx on Orders (o_orderdate); |
| 72 | |
| 73 | declare 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 | |
| 81 | for $o in dataset('Orders') |
| 82 | for $t in tmp() |
| 83 | where $o.o_orderkey = $t.o_orderkey and |
| 84 | $o.o_orderdate >= '1993-07-01' and $o.o_orderdate < '1993-10-01' |
| 85 | group by $o_orderpriority := $o.o_orderpriority with $o |
| 86 | order by $o_orderpriority |
| 87 | return { |
| 88 | "order_priority": $o_orderpriority, |
| 89 | "count": count($o) |
| 90 | } |
| 91 | |
| 92 | |
| 93 | drop dataverse tpch if exists; |
| 94 | drop nodegroup group_test if exists; |