Ian Maxon | 857dc13 | 2015-09-25 17:13:19 -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 | */ |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 19 | drop dataverse tpch if exists; |
| 20 | create dataverse tpch; |
| 21 | use dataverse tpch; |
| 22 | |
| 23 | create type LineItemType as closed { |
| 24 | l_orderkey: int32, |
| 25 | l_partkey: int32, |
| 26 | l_suppkey: int32, |
| 27 | l_linenumber: int32, |
| 28 | l_quantity: double, |
| 29 | l_extendedprice: double, |
| 30 | l_discount: double, |
| 31 | l_tax: double, |
| 32 | l_returnflag: string, |
| 33 | l_linestatus: string, |
| 34 | l_shipdate: string, |
| 35 | l_commitdate: string, |
| 36 | l_receiptdate: string, |
| 37 | l_shipinstruct: string, |
| 38 | l_shipmode: string, |
| 39 | l_comment: string |
| 40 | } |
| 41 | |
| 42 | create type OrderType as closed { |
| 43 | o_orderkey: int32, |
| 44 | o_custkey: int32, |
| 45 | o_orderstatus: string, |
| 46 | o_totalprice: double, |
| 47 | o_orderdate: string, |
| 48 | o_orderpriority: string, |
| 49 | o_clerk: string, |
| 50 | o_shippriority: int32, |
| 51 | o_comment: string |
| 52 | } |
| 53 | |
| 54 | create type CustomerType as closed { |
| 55 | c_custkey: int32, |
| 56 | c_name: string, |
| 57 | c_address: string, |
| 58 | c_nationkey: int32, |
| 59 | c_phone: string, |
| 60 | c_acctbal: double, |
| 61 | c_mktsegment: string, |
| 62 | c_comment: string |
| 63 | } |
| 64 | |
| 65 | |
| 66 | create type PartSuppType as closed { |
| 67 | ps_partkey: int32, |
| 68 | ps_suppkey: int32, |
| 69 | ps_availqty: int32, |
| 70 | ps_supplycost: double, |
| 71 | ps_comment: string |
| 72 | } |
| 73 | |
| 74 | |
| 75 | create nodegroup group1 if not exists on nc1, nc2; |
| 76 | |
| 77 | create dataset LineItems(LineItemType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 78 | primary key l_orderkey, l_linenumber on group1; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 79 | create dataset Orders(OrderType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 80 | primary key o_orderkey on group1; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 81 | create dataset Customers(CustomerType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 82 | primary key c_custkey on group1; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 83 | create dataset PartSupp(PartSuppType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 84 | primary key ps_partkey, ps_suppkey on group1; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 85 | |
| 86 | write output to nc1:"/tmp/nested_loj.adm"; |
| 87 | |
| 88 | for $c in dataset('Customers') |
| 89 | let $orders := |
| 90 | for $o in dataset('Orders') |
| 91 | where $o.o_custkey = $c.c_custkey |
| 92 | let $items := |
| 93 | for $l in dataset('LineItems') |
| 94 | where $l.l_orderkey = $o.o_orderkey |
| 95 | let $partsupp := |
| 96 | for $ps in dataset('PartSupp') |
| 97 | where $ps.ps_partkey = $l.l_partkey and $ps.ps_suppkey = $l.l_suppkey |
| 98 | return $ps |
| 99 | return { |
| 100 | "item": $l, |
| 101 | "part_supplier": $partsupp |
| 102 | } |
| 103 | return { |
| 104 | "order": $o, |
| 105 | "items": $items |
| 106 | } |
| 107 | return { |
| 108 | "cust": $c, |
| 109 | "orders": $orders |
| 110 | } |