blob: d82a2b83358be14127197539752afbaba6683d13 [file] [log] [blame]
Yingyi Bue3e13732015-12-30 16:06:04 -08001/*
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
21drop dataverse emergencyTest if exists;
22create dataverse emergencyTest;
23use dataverse emergencyTest;
24
25create type CHPReport as
26{ "rid":uuid, "epicenter":point, "radius":double }
27
28create type userLocation as
29{ "id":uuid, "user-id":int64, "location":point }
30
31create type tornadoShelter as
32{ "tsid":uuid, "location":point }
33
34create type sub as closed
35{ "id":int, "param0":int64 }
36
37create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub)
38primary key id;
39
40create dataset tornadoShelters(tornadoShelter)
41primary key tsid autogenerated;
42
43create dataset userLocations(userLocation)
44primary key id autogenerated;
45
46create dataset CHPReports(CHPReport)
47primary key rid autogenerated;
48
49
50create function NearbySheltersDuringTornadoDanger($userid) {
51 for $emergency in dataset CHPReports
52 let $dangerzone := create-circle($emergency.epicenter,$emergency.radius)
53 where (some $user in dataset userLocations satisfies $user.user-id = $userid)
54 //and spatial-intersect($dangerzone,$user.location))
55 /** This test comments out the spatial-intersect function to test
56 * if it will results in a hybrid hash join.
57 * query-ASTERIXDB-1017-2 is the same as this query except
58 * that the spatial-intersect function is enabled.
59 */
60 return
61 { "shelter locations":for $shelter in dataset tornadoShelters return $shelter.location}
62};
63
64
65for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
66for $result in NearbySheltersDuringTornadoDanger($sub.param0)
67return
68{ "subscription-id":$sub.subscription-id,"execution-time":current-datetime(),"result":$result }
69;