在 hive 查询中使用 map/reduce java 类 [英] Using map/reduce java classes in hive queries
问题描述
我读到,在 hive 查询中,我们可以使用 map/reduce 脚本.
I read like, in hive queries we can use map/reduce scripts.
我们可以在 Hive 查询中使用 java map/reduce 类吗?如果是这样,请您提供样品给我.
Can we use java map/reduce classes in Hive queries. If so, can you please provide me the sample.
谢谢MRK
推荐答案
您可以按照 链接 由@Moiz Arafat 提供.
You can start writing you custom Mapper and Reducer following the Link provided by @Moiz Arafat.
然后用它制作一个罐子(比如 myjar.jar).
After that make a jar out of it (say myjar.jar).
此类自定义 Mapper 和 Reducer 的工作需要 hive-contrib.jar,可以在 hive 安装的 lib 文件夹中找到.
Working of such custom Mapper and Reducer require hive-contrib.jar, which can be found in the lib folder of your hive installation.
在运行使用这些 Mapper/Reducer 的查询之前,您应该将这两个 jars 添加到 hive.
Before running a query which uses these Mapper/Reducer, you should add these two jars to hive.
hive> add file path/to/hive-contrib.jar;
hive> add file path/to/myjar.jar;
请使用添加文件而不是添加jar.
现在您可以编写如下查询:
Now you can write your query like :
hive> FROM (
FROM src
MAP inkey, inval
USING 'java -cp myjar.jar:hive-contrib.jar com.myco.mymr.MyMapper'
AS k, v
CLUSTER BY k) mapout
REDUCE k, v
USING 'java -cp myjar.jar:hive-contrib.jar com.myco.mymr.MyReducer'
这篇关于在 hive 查询中使用 map/reduce java 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!