【发布时间】:2014-04-17 04:18:26
【问题描述】:
以下是我正在使用的 HIVE 查询,我也在使用排名功能。我在本地机器上运行它。
SELECT numeric_id, location, Rank(location), followers_count
FROM (
SELECT numeric_id, location, followers_count
FROM twitter_data
DISTRIBUTE BY numeric_id, location
SORT BY numeric_id, location, followers_count desc
) a
WHERE Rank(location)<10;
我的Rank函数如下:
package org.apache.hadoop.hive.contrib.udaf.ex;
import org.apache.hadoop.hive.ql.exec.UDF;
public final class Rank extends UDF{
private int counter;
private String last_key;
public int evaluate(final String key){
if ( !key.equalsIgnoreCase(this.last_key) ) {
this.counter = 0;
this.last_key = key;
}
return this.counter++;
}
}
我正在创建上述文件的 Jar,然后在运行 hive 查询之前执行以下步骤。我试着用可运行的 jar 来做,也用一个简单的方法来创建。
ADD JAR /home/adminpc/Downloads/Project_input/Rank.jar;
CREATE TEMPORARY FUNCTION Rank AS 'org.apache.hadoop.hive.contrib.udaf.ex.Rank';
这是我在执行 Hive 查询后得到的——
hive> SELECT numeric_id, location, Rank(location), followers_count
> FROM (
> SELECT numeric_id, location, followers_count
> FROM twitter_data
> DISTRIBUTE BY numeric_id, location
> SORT BY numeric_id, location, followers_count desc
> ) a
> WHERE Rank(location)<1;
FAILED: NullPointerException null
【问题讨论】:
-
任何人。孤独星球的帮助!
-
我也面临同样的问题。你找到解决方案了吗..@patz
-
@Manindar sry 老兄,应该更新了这个问题,已经 2 年了,我几乎不记得解决方案了。
-
我找到了解决方案。我正在使用 UDAF,并且只覆盖了 3 种方法。即
i) init() ii) iterate() iii) terminate()。现在我更新了我的代码以覆盖强制拥有的 5 种方法。i) init() ii) iterate() iii) terminatePartial() iv) terminate() v) merge()。有了这个我解决了我的问题。
标签: hadoop mapreduce hive elastic-map-reduce hiveql