Apache配置单元窗口函数滞后和超前错误

时间:2016-05-03 06:05:25

标签: hadoop apache-hive

我正在尝试使用LAG和LEAD函数从列中选择前导和滞后值。以下是表格和数据。

hive> select * from foo;                                                      
OK
a
1
2
3
4
5
6
7
8
9
Time taken: 0.923 seconds

当我尝试选择超前和滞后值时,会抛出以下错误。

hive> select LAG(a, 1) over (order by a) as previous, a, LEAD(a, 1) over (order by a) as next from foo;
FAILED: ParseException line 1:22 missing FROM at '(' near '(' in subquery source
line 1:23 cannot recognize input near 'order' 'by' 'a' in subquery source

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我可以看到"分区"声明中缺少该条款。

Select lead(a,1) over (partition by a order by a) as next from foo;

如果您有更多的列,如日期/时间,类别,它将无效,只有在表中的一列上运行才有用。