在配置单元查询中使用map / reduce java类 [英] Using map/reduce java classes in hive queries

查看:123
本文介绍了在配置单元查询中使用map / reduce java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过,在hive查询中,我们可以使用map / reduce脚本。



我们可以在Hive查询中使用java map / reduce类。如果是这样,你可以给我提供样品。



感谢
MRK

解决方案

您可以按照链接由@Moiz Arafat提供。



之后,制作一个罐子(比如myjar.jar)。



这样的自定义Mapper和Reducer的工作需要hive-contrib.jar,它可以在您的hive安装的lib文件夹中找到。



在运行使用这些Mapper / Reducer的查询之前,您应该将这两个jar添加到配置单元。

  hive>添加文件路径/ to / hive-contrib.jar; 
hive>添加文件路径/ to / myjar.jar;

请使用添加文件,而不是添加jar

现在你可以编写你的查询了:

  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
使用'java -cp myjar.jar:hive-contrib.jar com.myco.mymr.MyReducer'


I read like, in hive queries we can use map/reduce scripts.

Can we use java map/reduce classes in Hive queries. If so, can you please provide me the sample.

Thanks MRK

解决方案

You can start writing you custom Mapper and Reducer following the Link provided by @Moiz Arafat.

After that make a jar out of it (say myjar.jar).

Working of such custom Mapper and Reducer require hive-contrib.jar, which can be found in the lib folder of your hive installation.

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;

Please use add file and NOT add 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'

这篇关于在配置单元查询中使用map / reduce java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆