/*
 * 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.
 */
use dataverse events;

declare type EventType as closed {
  event_id: int64, 
  name: string,
  location: AddressType	?,
  organizers: {{ 
   {
     name: string
   }
  }},
  sponsoring_sigs: [
    {
      sig_id: int32,
      chapter_name: string
    }
  ],
  interest_keywords: {{string}},
  price: double?,
  start_time: datetime,
  end_time: datetime
}

declare type AddressType as closed {
  street: string,
  city: string,
  zip: string,
  latlong: point
}

declare nodegroup group1 on asterix_nc1;

/*
declare dataset Event(EventType) 
  splits asterix_nc1:"/home/nicnic/Work/Asterix/adg/event.adm";
*/

drop dataset Event;
declare dataset Event(EventType) 
  primary key event_id on group1;

load dataset Event 
using localfs
(("path"="asterix_nc1:///home/nicnic/Work/Asterix/adg/event.adm"),("format"="adm"));

write output to asterix_nc1:"/tmp/dapd_q2.adm";

for $event in dataset('Event')
for $sponsor in $event.sponsoring_sigs
let $es := { "event": $event, "sponsor": $sponsor }
group by $sig_id := $sponsor.sig_id with $es
let $sig_sponsorship_count := count($es)
let $by_chapter :=
   for $e in $es
   group by $chapter_name := $e.sponsor.chapter_name with $e
   return { "chapter_name": $chapter_name, "escount" : count($e) }
order by $sig_sponsorship_count desc
limit 5
return { "sig_id": $sig_id, "total_count": $sig_sponsorship_count, "chapter_breakdown": $by_chapter }

