我如何编译Hive UDF [英] How do I compile a Hive UDF

查看:141
本文介绍了我如何编译Hive UDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译这个UDF:

  package com.dataminelab.hive.udf; 
导入org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
import java.security。*;
$ b $ / **
*计算字符串
* /
的md5 public final class Md5 extends UDF {

public Text evaluate(最终文本s){
if(s == null){
return null;
}
尝试{
MessageDigest md = MessageDigest.getInstance(MD5);
md.update(s.toString()。getBytes());
byte [] md5hash = md.digest();
StringBuilder builder = new StringBuilder();
for(byte b:md5hash){
builder.append(Integer.toString((b& 0xff)+ 0x100,16).substring(1));
}
return new Text(builder.toString());
} catch(NoSuchAlgorithmException nsae){
System.out.println(Can not find digest algorithm);
System.exit(1);
}
返回null;


尝试使用以下内容进行编译:

  javac Md5.java 

但我得到:

  Md5.java:2:package org.apache.hadoop.hive.ql.exec不存在
导入org.apache.hadoop.hive.ql.exec.UDF;
^
Md5.java:3:包org.apache.hadoop.io不存在
import org.apache.hadoop.io.Text;

我假设这些文件位于某个jar文件中,但我不确定hadoop在哪里安装它们我不能将它们添加到我的类路径中。有没有人知道默认位置或如何找出?

解决方案

以下对我有用,但我怀疑细节会有所不同取决于你的安装和你的源代码的功能:



pre $ export CLASSPATH = / usr / lib / hive / lib / hive-exec -0.9.0.15.jar:/usr/lib/hadoop/hadoop-core.jar


I am trying to compile this UDF:

package com.dataminelab.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
import java.security.*;

/**
 * Calculate md5 of the string
*/
public final class Md5 extends UDF {

    public Text evaluate(final Text s) {
        if (s == null) {
            return null;
        }
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(s.toString().getBytes());
            byte[] md5hash = md.digest();
            StringBuilder builder = new StringBuilder();
            for (byte b : md5hash) {
            builder.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
            }
            return new Text(builder.toString());
            } catch (NoSuchAlgorithmException nsae) {
            System.out.println("Cannot find digest algorithm");
            System.exit(1);
        }
        return null;
    }
}

Trying to compile with:

javac Md5.java

But I get:

Md5.java:2: package org.apache.hadoop.hive.ql.exec does not exist
import org.apache.hadoop.hive.ql.exec.UDF;
                                     ^
Md5.java:3: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.Text;

I assume these are in a jar file somewhere but I'm not sure where hadoop install them to so I can't add them to my classpath. Does anyone know the default location or how to find out?

解决方案

The following works for me, but I suspect the details will vary depending on your installation and what your source code does:

export CLASSPATH=/usr/lib/hive/lib/hive-exec-0.9.0.15.jar:/usr/lib/hadoop/hadoop-core.jar

这篇关于我如何编译Hive UDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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