title: Spark - "partial" Window function
body: <p>In Spark trying to do "partial" window function.</p>
  
  <p>Giving schema <strong>eventId, impressionTime, campaign, revenue</strong>, I would like to know for each evenId the sum of revenue for the campaign in last 4 days.</p>
  
  <p>At the end, I am only inserting in last 3 days. So I had to load 7 days of data (so the earliest event has the 4 days window) and the problem is that I will calculate also for the events out of my final range.</p>
  
  <p>Small example:
  I have data for 7 days (day1, day2, day3, day4, day5, day6, day7 7 is the later) and in the output only days: 7,6,5 are required.</p>
  
  <p>I need the window for every 4 days. So I will load all the days and do window function for them. At the end I will take last only 3 days.  </p>
  
  <p>Of course this is very inefficient, since I calculate the window also for
  days 4,3...</p>
  
  <p>Is there anyway to do window function on some of the data? </p>
  
  <p>Thanks</p>