1

I would like to subtract a number from the hive variable passed. For example:

SET hiveconf:window_size = 12
SELECT id , max(marks) OVER(ORDER BY Date_time ROWS BETWEEN ${hiveconf:window_size}-1 PRECEDING AND CURRENT ROW) from Students;

But ${hiveconf:window_size}-1 in window function is giving error.

Can anyone provide any suggestions on this.

Kishore
  • 5,761
  • 5
  • 28
  • 53
  • See https://community.hortonworks.com/articles/60309/working-with-variables-in-hive-hive-shell-and-beel.html – Harold Aug 14 '18 at 12:20

1 Answers1

1

It does not like inline calculation of ROWS BETWEEN boundary. Subtract 1 before executing query.

This will work:

SET hiveconf:window_size=11;
SELECT id , max(marks) OVER(ORDER BY Date_time ROWS BETWEEN ${hiveconf:window_size} PRECEDING AND CURRENT ROW) from Students
;

Alternatively you can calculate it in the shell and pass to the Hive script as a variable. See here how to pass a variable from the shell: https://stackoverflow.com/a/37821218/2700344

leftjoin
  • 36,950
  • 8
  • 57
  • 116