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