title: Compute Moving Exponential Average in HIVE
body: <p>I'm trying to calculate exponential average in hive. 
  For EMA, it's 
  EMA = (K * (C - P)) + P in which K is the smoothing factor, suppose it's 0.5. C is the current value, p is the previous value. If a table is like the table shown below:</p>
  
  <pre><code>ID    Value        Date
  1      10         2010-05-03
  2      15         2010-05-06
  3      17         2010-05-13
  </code></pre>
  
  <p>And the EMA should be:</p>
  
  <pre><code>ID     EMA                             Date
  1      10                           2010-05-03
  2   0.5*(15 - 10) + 10 = 12.5       2010-05-06
  3   0.5*(17 - 12.5) + 12.4 = 14.75  2010-05-13
  </code></pre>
  
  <p>Instead of implementing UDF in Java, I'm thinking if just by using Hive SQL build in functions can I get the same results. I think LAG function should be applied here, but I'm really not good at database... So am I in the right direction? Is there a Hive SQL like way to do this?</p>
  
  <p>Thanks a lot!!</p>