Given a Hive table like below I want to calculate a weighted moving average. In table 1 is an example of such a weighted moving average. The value of every column is
col_value = (1 * n) + (0.75 * n-1) + (0.5 * n-2) + (0.25 * n-3)
where n is the value at the current row, n-1 the value at the above row, etc.
More info on weighted moving averages on the corresponding Wikipedia section
Im stuck after calculating the moving average like so:
Code sample 1: Query so far
SELECT
*,
AVG (value) OVER (
ORDER BY
id
ROWS BETWEEN
3 PRECEDING AND CURRENT ROW
FROM
table
Table 1:
id value weighted_moving_average code_sample_1
...
11 0 0 0
12 1 1 0.25
13 0 0.75 0.25
14 0 0.5 0.25
15 0 0.25 0.25
16 0 0 0
...