| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| drop dataverse channels if exists; |
| create dataverse channels; |
| use channels; |
| |
| create type UserLocation as { |
| location: circle, |
| userName: string |
| }; |
| |
| |
| create type EmergencyReport as { |
| reportId: uuid, |
| Etype: string, |
| location: circle |
| }; |
| |
| |
| create type EmergencyShelter as { |
| shelterName: string, |
| location: point |
| }; |
| |
| create dataset UserLocations(UserLocation) |
| primary key userName; |
| create dataset Shelters(EmergencyShelter) |
| primary key shelterName; |
| create dataset Reports(EmergencyReport) |
| primary key reportId autogenerated; |
| |
| create index u_location on UserLocations(location) type RTREE; |
| |
| |
| create function RecentEmergenciesNearUser(userName) { |
| select report, shelters from |
| (select value r from Reports r)report, |
| UserLocations u |
| let shelters = (select s.location from Shelters s where spatial_intersect(s.location,u.location)) |
| where u.userName = userName |
| and spatial_intersect(report.location,u.location) |
| }; |
| |
| create repetitive channel EmergencyChannel using RecentEmergenciesNearUser@1 period duration("PT10S"); |
| |
| create broker brokerA at "http://www.notifyA.com"; |