/*
 * 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 nc1;

/*
declare dataset Event(EventType) 
  splits 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"="nc1:///home/nicnic/Work/Asterix/adg/event.adm"),("format"="adm"));

write output to 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 }

