Using map/reduce java classes in hive queries

2019-02-25 03:50发布

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

标签: hive
3条回答
劫难
2楼-- · 2019-02-25 04:25

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'
查看更多
Animai°情兽
3楼-- · 2019-02-25 04:27

Assume you have created your "MyMapper" and "MyReducer" classes and put them in a "mymr.jar" jar file. You can use them through streaming as such:

FROM (
FROM src
MAP inkey, inval
USING 'java -cp myjar.jar
com.myco.mymr.MyMapper'
AS k, v
CLUSTER BY k) mapout
REDUCE k, v
USING 'java -cp myjar.jar
com.myco.mymr.MyReducer'
查看更多
男人必须洒脱
4楼-- · 2019-02-25 04:34

Refer the url . It should help . Link

查看更多
登录 后发表回答