首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >配置单元UDF在select中抛出未找到类异常

配置单元UDF在select中抛出未找到类异常
EN

Stack Overflow用户
提问于 2017-08-06 21:36:45
回答 1查看 1.1K关注 0票数 0

我一直在使用UDF jar。我需要在我的UDF中解析简单的UserAgent。我发现了一个流行的UserAgent解析器http://www.bitwalker.eu/software/user-agent-utils,我将其包含在我的项目中。在项目中,我使用maven。我添加了所有依赖项,实现了所有内容并对其进行了测试。它在我的本地机器上运行得很好。接下来,我在maven中为构建jar做了干净的安装。我通过添加jar {MyJarName}在配置单元中使用了这个jar,然后创建了一个函数:将临时函数{functionName}创建为{pathToUDFClass},并得到如下异常。

代码语言:javascript
复制
Caused by: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"bidid":"8326c0ec49e5746f1af03400f37e5797","tstamp":20131022185001163,"logtype":1
,"ipinyouid":"D89E8S5bwWz","useragent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; InfoPath.2)","ip":"61.138.253.*","regionid":374,"cityid":375,"adexchange":1
,"domain":"449a7568331085d43d5867de26ce1ee1","url":"5ecba5b62bafd3428cdc1398b40cf88f","anonymousurl":"null","adslotid":null,"adslotwidth":300,"adslotheight":250,"adslotvisibility":"Na","adslotformat":"Na","adslo
tfloorprice":0,"creativeid":"10722","biddingprice":294,"payingprice":135,"landingpageurl":"null","advertiserid":2821,"userprofileids":[10006,10110,10063]}                                                         
        at org.apache.hadoop.hive.ql.exec.tez.MapRecordSource.processRow(MapRecordSource.java:91)                                                                                                                  
        at org.apache.hadoop.hive.ql.exec.tez.MapRecordSource.pushRecord(MapRecordSource.java:68)                                                                                                                  
        at org.apache.hadoop.hive.ql.exec.tez.MapRecordProcessor.run(MapRecordProcessor.java:325)                                                                                                                  
        at org.apache.hadoop.hive.ql.exec.tez.TezProcessor.initializeAndRunProcessor(TezProcessor.java:150)                                                                                                        
        ... 14 more                                                                                                                                                                                                
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"bidid":"8326c0ec49e5746f1af03400f37e5797","tstamp":20131022185001163,"logtype":1,"ipinyouid":"D89E8S5bwWz","
useragent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; InfoPath.2)","ip":"61.138.253.*","regionid":374,"cityid":375,"adexchange":1,"domain":"449a7568331085d43
d5867de26ce1ee1","url":"5ecba5b62bafd3428cdc1398b40cf88f","anonymousurl":"null","adslotid":null,"adslotwidth":300,"adslotheight":250,"adslotvisibility":"Na","adslotformat":"Na","adslotfloorprice":0,"creativeid":
"10722","biddingprice":294,"payingprice":135,"landingpageurl":"null","advertiserid":2821,"userprofileids":[10006,10110,10063]}                                                                                     
        at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:565)                                                                                                                                
        at org.apache.hadoop.hive.ql.exec.tez.MapRecordSource.processRow(MapRecordSource.java:83)                                                                                                                  
        ... 17 more                                                                                                                                                                                                
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public org.apache.hadoop.io.Text hive.homework3.UserAgentDetector.evaluate(org.apache.hadoop.io.Text)  on object hive.homewor
k3.UserAgentDetector@1b340ab of class hive.homework3.UserAgentDetector with arguments {Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; InfoPath.2):org.apache.hadoo
p.io.Text} of size 1                                                                                                                                                                                               
        at org.apache.hadoop.hive.ql.exec.FunctionRegistry.invoke(FunctionRegistry.java:1019)                                                                                                                      
        at org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge.evaluate(GenericUDFBridge.java:182)                                                                                                              
        at org.apache.hadoop.hive.ql.exec.ExprNodeGenericFuncEvaluator._evaluate(ExprNodeGenericFuncEvaluator.java:186)                                                                                            
        at org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator.evaluate(ExprNodeEvaluator.java:77)                                                                                                                    
        at org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator.evaluate(ExprNodeEvaluator.java:65)                                                                                                                    
        at org.apache.hadoop.hive.ql.exec.SelectOperator.process(SelectOperator.java:81)                                                                                                                           
        at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:841)                                                                                                                                      
        at org.apache.hadoop.hive.ql.exec.TableScanOperator.process(TableScanOperator.java:133)                                                                                                                    
        at org.apache.hadoop.hive.ql.exec.MapOperator$MapOpCtx.forward(MapOperator.java:170)                                                                                                                       
        at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:555)                                                                                                                                
        ... 18 more                                                                                                                                                                                                
Caused by: java.lang.reflect.InvocationTargetException                                                                                                                                                             
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                                             
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                                                                                                           
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                                   
        at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                                                                        
        at org.apache.hadoop.hive.ql.exec.FunctionRegistry.invoke(FunctionRegistry.java:995)                                                                                                                       
        ... 27 more                                                                                                                                                                                                
Caused by: java.lang.NoClassDefFoundError: eu/bitwalker/useragentutils/UserAgent                                                                                                                                   
        at hive.homework3.UserAgentDetector.formatter(UserAgentDetector.java:30)                                                                                                                                   
        at hive.homework3.UserAgentDetector.evaluate(UserAgentDetector.java:22)                                                                                                                                    
        ... 32 more                                                                                                                                                                                                
Caused by: java.lang.ClassNotFoundException: eu.bitwalker.useragentutils.UserAgent                                                                                                                                 
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)                                                                                                                                              
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)                                                                                                                                                   
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)                                                                                                                                           
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)                                                                                                                                                   
        ... 34 more                                                                                                                                                                                                
]], Vertex did not succeed due to OWN_TASK_FAILURE, failedTasks:1 killedTasks:21, Vertex vertex_1501829365845_0009_1_00 [Map 1] killed/failed due to:OWN_TASK_FAILURE]DAG did not succeed due to VERTEX_FAILURE. fa
iledVertices:1 killedVertices:0  

据我所知,最重要的事情是:

代码语言:javascript
复制
Caused by: java.lang.ClassNotFoundException: eu.bitwalker.useragentutils.UserAgent                                                                                                                                 
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)                                                                                                                                              
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)                                                                                                                                                   
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)                                                                                                                                           
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)                                                                                                                                                   
        ... 34 more      

这是我在maven项目中使用的外部库。

这是UDF创建,顺便说一句,在本地工作中,一切正常和测试都通过了。但在蜂巢里它不起作用。我想我使用的这个库有问题,但是如果我在本地工作得很好,这是可能的吗?

代码语言:javascript
复制
import eu.bitwalker.useragentutils.UserAgent;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;


@Description(
        name = "agentdetector",
        value = "_FUNC_(str) - detects a user-agent of user",
        extended = "Example:\n" +
                " > SELECT agent(line) FROM test ipy; \n"
)
public class UserAgentDetector extends UDF {

    public Text evaluate(Text text) {
        Text value = new Text("");
        if (text != null) {
            value.set(formatter(text));
            return value;
        } else {
            return null;
        }
    }

    private Text formatter(Text text) {
        UserAgent userAgent = UserAgent.parseUserAgentString(text.toString());
        StringBuilder builder = new StringBuilder();
        builder.append("Browser : ").append(userAgent.getBrowser().getName()).append("\n");
        text.set(builder.toString());
        return text;
    }

maven的依赖关系是:

代码语言:javascript
复制
 <dependency>
            <groupId>eu.bitwalker</groupId>
            <artifactId>UserAgentUtils</artifactId>
            <version>1.20</version>
  </dependency>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-07 01:26:38

要解决这个问题,只需在您的pom.xml中添加插件

代码语言:javascript
复制
           <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>{pathToMainClass}</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

和运行汇编: maven插件中的汇编。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45532559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档