Steven Glenn Jacobs | 345b0f5 | 2018-04-12 13:19:50 -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 | * Description : Check a push-based channel plan |
| 21 | * Expected Res : Success |
| 22 | * Date : Mar 2018 |
| 23 | */ |
| 24 | |
| 25 | drop dataverse channels7 if exists; |
| 26 | create dataverse channels7; |
| 27 | use channels7; |
| 28 | |
| 29 | create type UserLocation as { |
| 30 | location: circle, |
| 31 | userName: string, |
| 32 | timeStamp: datetime |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | create type UserLocationFeedType as { |
| 37 | location: circle, |
| 38 | userName: string |
| 39 | }; |
| 40 | |
| 41 | create type EmergencyReport as { |
| 42 | reportId: uuid, |
| 43 | Etype: string, |
| 44 | location: circle, |
| 45 | timeStamp: datetime |
| 46 | }; |
| 47 | |
| 48 | create type EmergencyReportFeedType as { |
| 49 | Etype: string, |
| 50 | location: circle |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | create type EmergencyShelter as { |
| 55 | shelterName: string, |
| 56 | location: point |
| 57 | }; |
| 58 | |
| 59 | create dataset UserLocations(UserLocation) |
| 60 | primary key userName; |
| 61 | create dataset Shelters(EmergencyShelter) |
| 62 | primary key shelterName; |
| 63 | create dataset Reports(EmergencyReport) |
| 64 | primary key reportId autogenerated; |
| 65 | |
| 66 | create index location_time on UserLocations(timeStamp); |
| 67 | create index u_location on UserLocations(location) type RTREE; |
| 68 | create index s_location on Shelters(location) type RTREE; |
| 69 | create index report_time on Reports(timeStamp); |
| 70 | |
| 71 | create function RecentEmergenciesNearUser(userName) { |
| 72 | ( |
| 73 | select report, shelters from |
| 74 | ( select value r from Reports r where r.timeStamp > |
| 75 | current_datetime() - day_time_duration("PT10S"))report, |
| 76 | UserLocations u |
| 77 | let shelters = (select s.location from Shelters s where spatial_intersect(s.location,u.location)) |
| 78 | where u.userName = userName |
| 79 | and spatial_intersect(report.location,u.location) |
| 80 | ) |
| 81 | }; |
| 82 | |
| 83 | write output to nc1:"rttest/channel-push.sqlpp"; |
| 84 | |
| 85 | create repetitive push channel EmergencyChannel using RecentEmergenciesNearUser@1 period duration("PT10S"); |