title: Need to calculate average per user for a 30 day history for each user using hive
body: <p>I am confused about my datamodel. i.e if I need to use a UDAF to solve this and how hive deals with this when it comes down to splitting the task.</p>
  
  <p>Problem statement: I need to compute the average(slightly different version then what is available so it needs to be a custom formula) per user based on events that are from 30 days as I look back in time. So I have my data in the form of:</p>
  
  <blockquote>
    <p>userid date counts<br>
    user1  day30  34<br>
    user1  day30  23<br>
    user1  day4   22<br>
    user1  day1   21<br>
    user2  day30  23<br>
    user2  day23  12<br>
    usern ....</p>
  </blockquote>
  
  <p>What I need as a ouput is the following:</p>
  
  <blockquote>
    <p>user1 avg: (34+23+22+21...)/30<br>
    user2 avg: (23+12...)/30  </p>
  </blockquote>
  
  <p>What is the most memory efficient way to approach this problem? I probably need to use a udf but how does this work with a user with a lot of rows? Does the UDAF deal with this per user or do I need to do something like restrict all rows pertaining to one user in a reducer. Thanks! </p>