Yingyi Bu | e3e1373 | 2015-12-30 16:06:04 -0800 | [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 | |
| 21 | drop dataverse emergencyTest if exists; |
| 22 | create dataverse emergencyTest; |
| 23 | use dataverse emergencyTest; |
| 24 | |
| 25 | create type CHPReport as |
| 26 | { "rid":uuid, "epicenter":point, "radius":double } |
| 27 | |
| 28 | create type userLocation as |
| 29 | { "id":uuid, "user-id":int64, "location":point } |
| 30 | |
| 31 | create type tornadoShelter as |
| 32 | { "tsid":uuid, "location":point } |
| 33 | |
| 34 | create type sub as closed |
| 35 | { "id":int, "param0":int64 } |
| 36 | |
| 37 | create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub) |
| 38 | primary key id; |
| 39 | |
| 40 | create dataset tornadoShelters(tornadoShelter) |
| 41 | primary key tsid autogenerated; |
| 42 | |
| 43 | create dataset userLocations(userLocation) |
| 44 | primary key id autogenerated; |
| 45 | |
| 46 | create dataset CHPReports(CHPReport) |
| 47 | primary key rid autogenerated; |
| 48 | |
| 49 | |
| 50 | create 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 | |
| 65 | for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions |
| 66 | for $result in NearbySheltersDuringTornadoDanger($sub.param0) |
| 67 | return |
| 68 | { "subscription-id":$sub.subscription-id,"execution-time":current-datetime(),"result":$result } |
| 69 | ; |