blob: 9f9d60961a7bfc63378c4bfa86c119f8831af90a [file] [log] [blame]
Yingyi Bu391f09e2015-10-29 13:49:39 -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 database TinySocial if exists;
21create database TinySocial;
22
23use TinySocial;
24
25
26create type TinySocial.EmploymentType as
27{
28 "organization-name" : string,
29 "start-date" : date,
30 "end-date" : date?
31}
32
33create 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
43create table FacebookUsers(FacebookUserType) primary key id;
44
45with 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 )
55select element {'user1':{'id':l1.id,'name':l1.name},'user2':{'id':l2.id,'name':l2.name}}
56from lonelyusers as l1,
57 lonelyusers2 as l2
58where (l1.id < l2.id)
59order by l1.id,l2.id
60;