/*
 * 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 "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"
(("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 }

