title: How to group by time interval in Spark SQL
body: <p>My dataset looks like this: </p>
  
  <pre><code>KEY |Event_Type | metric | Time 
  001 |event1     | 10     | 2016-05-01 10:50:51
  002 |event2     | 100    | 2016-05-01 10:50:53
  001 |event3     | 20     | 2016-05-01 10:50:55
  001 |event1     | 15     | 2016-05-01 10:51:50
  003 |event1     | 13     | 2016-05-01 10:55:30
  001 |event2     | 12     | 2016-05-01 10:57:00
  001 |event3     | 11     | 2016-05-01 11:00:01
  </code></pre>
  
  <p>I want to get all when the keys that verify this: </p>
  
  <p><strong>"SUM of metric for a specific event"</strong> > <strong>threshold</strong> during <strong>5 minutes</strong> . </p>
  
  <p>This appear to me a perfect candidate for using the <strong>Sliding Windows Functions</strong> . </p>
  
  <p>How can I do this with Spark SQL ? </p>
  
  <p>Thank you.</p>