Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -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 database TinySocial if exists; |
| 21 | create database TinySocial; |
| 22 | |
| 23 | use TinySocial; |
| 24 | |
| 25 | |
| 26 | create type TinySocial.EmploymentType as |
| 27 | { |
| 28 | "organization-name" : string, |
| 29 | "start-date" : date, |
| 30 | "end-date" : date? |
| 31 | } |
| 32 | |
| 33 | create type TinySocial.FacebookUserType as |
| 34 | closed { |
| 35 | id : int32, |
| 36 | alias : string, |
| 37 | name : string, |
| 38 | "user-since" : datetime, |
| 39 | "friend-ids" : {{int32}}, |
| 40 | employment : [EmploymentType] |
| 41 | } |
| 42 | |
| 43 | create table FacebookUsers(FacebookUserType) primary key id; |
| 44 | |
| 45 | with lonelyusers as ( |
| 46 | select element d |
| 47 | from FacebookUsers as d |
| 48 | where (TinySocial.count(d."friend-ids") < 2) |
| 49 | ), |
| 50 | lonelyusers2 as ( |
| 51 | select element d |
| 52 | from FacebookUsers as d |
| 53 | where (TinySocial.count(d."friend-ids") < 2) |
| 54 | ) |
| 55 | select element {'user1':{'id':l1.id,'name':l1.name},'user2':{'id':l2.id,'name':l2.name}} |
| 56 | from lonelyusers as l1, |
| 57 | lonelyusers2 as l2 |
| 58 | where (l1.id < l2.id) |
| 59 | order by l1.id,l2.id |
| 60 | ; |