impala1.2.3 udf问题

简介:

新的impala已经支持udf了,在测试环境部署了1.2.3版本的cluster.
在运行测试udf时遇到下面这个错误:
java.lang.IllegalArgumentException (表明向方法传递了一个不合法或不正确的参数。)
经过确认这是一个bug:
https://issues.cloudera.org/browse/IMPALA-791
The currently impala 1.2.3 doesn't support String as the input and return types. You'll instead have to  use Text or BytesWritable.
1.2.3版本的impala udf的输入参数和返回值还不支持String,可以使用import org.apache.hadoop.io.Text类代替String

Text的api文档:
http://hadoop.apache.org/docs/current/api/org/apache/hadoop/io/Text.html
重要的几点:
Constructor:
Text(String string)    Construct from a string.
Method:
String     toString()    Convert text back to string
void     set(String string)  Set to contain the contents of a string.
void     set(Text other)  copy a text.
void     clear()  clear the string to empty

在eclipse中测试Text类的用法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package  com.hive.myudf;
import  java.util.Arrays;
import  java.util.regex.Pattern;
import  java.util.regex.Matcher;
import  org.apache.hadoop.io.Text;
public  class  TextTest {
     private  static  Text schemal =  new  Text(  "http://" );
     private  static  Text t =  new  Text(  "GET /vips-mobile/router.do?api_key=04e0dd9c76902b1bfc5c7b3bb4b1db92&app_version=1.8.7 HTTP/1.0" );
     private  static  Pattern p =  null ;
     private  static  Matcher m =  null ;
     public  static  void  main(String[] args) {
         p = Pattern. compile(  "(.+?) +(.+?) (.+)" );
         Matcher m = p.matcher( t.toString());
         if  (m.matches()){
                 String tt = schemal + "test.test.com"  +m.group( 2 );
                 System. out .println(tt);
                 //return m.group(2);
         else  {
                 System. out .println( "not match"  );
                 //return null;
         }
         schemal .clear();
         t.clear();
         }
}

测试udf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package  com.hive.myudf;
import  java.net.URL;
import  java.util.regex.Matcher;
import  java.util.regex.Pattern;
import  org.apache.hadoop.hive.ql.exec.UDF;
import  org.apache.hadoop.io.Text;
import  org.apache.log4j.Logger;
public  class  UDFNginxParseUrl  extends  UDF {
   private  static  final  Logger LOG = Logger.getLogger(UDFNginxParseUrl. class ); 
   private  Text schemal =  new  Text( "http://"  );
   private  Pattern p1 =  null ;
   private  URL url =  null ;
   private  Pattern p =  null ;
   private  Text lastKey =  null  ;
   private  String rt;
   public  UDFNginxParseUrl() {
   }
   public  Text evaluate(Text host1, Text urlStr, Text partToExtract) {
     LOG.debug(  "3args|args1:"  + host1 + ",args2:"  + urlStr +  ",args3:"  + partToExtract);
        System. out.println( "3 args"  );
        System. out.println( "args1:"  + host1 + ",args2:"  + urlStr +  ",args3:"  + partToExtract);
     if  (host1 ==  null  || urlStr ==  null  || partToExtract ==  null ) {
       //return null;
        return  new  Text( "a"  );
     }
      p1 = Pattern.compile( "(.+?) +(.+?) (.+)"  );
      Matcher m1 = p1.matcher(urlStr.toString());
      if  (m1.matches()){
          LOG.debug( "into match"  );
          String realUrl = schemal.toString() + host1.toString() + m1.group( 2 );
           Text realUrl1 =  new  Text(realUrl);
           System. out.println( "URL is "  + realUrl1);
           LOG.debug( "realurl:"  + realUrl1.toString());
           try {
                 LOG.debug( "into try"  );
                url =  new  URL(realUrl1.toString());
           catch  (Exception e){
                //return null;
                 LOG.debug( "into exception"  );
                 return  new  Text( "b"  );
           }
                            
      }
     if  (partToExtract.equals(  "HOST" )) {
       rt = url.getHost();
       LOG.debug(  "get host"  + rt );
     }
     //return new Text(rt);
     LOG.debug(  "get what" );
     return  new  Text( "rt"  );
   }
}

几个注意的地方:
1.function是和db相关联的。
2.jar文件存放在hdfs中
3.function会被catalog缓存



本文转自菜菜光 51CTO博客,原文链接:http://blog.51cto.com/caiguangguang/1359312,如需转载请自行联系原作者

相关文章
|
网络协议 Unix Linux
服务器实现端口转发的N种方式
服务器实现端口转发的N种方式
2032 0
|
安全 搜索推荐 数据建模
解决网站“不安全”、“不受信”、“排名下降”,你需要——「SSL证书」
SSL证书是网络安全的关键,用于加密和验证网站身份,保护用户数据安全,防止信息被窃取。它分为DV、OV、EV和IV四种类型,每种验证网站身份的程度不同。DV证书快速签发,OV和EV证书提供更高级别的身份验证,EV证书曾在浏览器地址栏显示绿色。目前,DV证书占据市场大部分份额。SSL证书还有单域、通配符和多域之分,有效期曾从多年逐渐缩短至90天,以增强安全性。部署SSL证书能提升用户信任,优化SEO排名,并符合网络安全法规要求。
解决网站“不安全”、“不受信”、“排名下降”,你需要——「SSL证书」
|
存储 前端开发 安全
webhook是什么 与API的区别在哪里
webhooks是一个api概念,是微服务api的使用范式之一,也被成为反向api,即:前端不主动发送请求,完全由后端推送。 举个常用例子,比如你的好友发了一条朋友圈,后端将这条消息推送给所有其他好友的客户端,就是 Webhooks 的典型场景。
webhook是什么 与API的区别在哪里
【图文】怎么配二级域名?怎么做URL重定向?
1、登录阿里云,进入控制台2、在左侧菜单找到域名》进入域名列表3、点击对应域名右侧的管理,进入单域名管理控制台4、选择域名解析5、点击右侧的添加记录6、这里就是关键了A记录就可以创建一个标准的二级域名;显性URL或隐性URL,就可以将一个域名、二级域名指向一个URL地址。
7023 0
|
3月前
|
人工智能 JSON 监控
阿里云可观测 2025 年 8 月产品动态
阿里云可观测 2025 年 8 月产品动态
181 26
|
2月前
|
机器学习/深度学习 人工智能 自然语言处理
41_涌现能力:从zero-shot到in-context学习
在人工智能领域,2022年以来,大语言模型(LLM)展现出的一系列惊人能力引发了广泛关注。其中最令人着迷的现象之一,就是**涌现能力**(Emergent Abilities)——当模型规模超过某个临界点时,突然表现出的在小模型中不存在的新能力。这种量变引发质变的神奇现象,彻底改变了我们对AI发展路径的认知。从最初只能进行简单文本生成的模型,到如今能够理解复杂指令、执行多步推理、甚至在未经过专门训练的任务上表现出色的AI系统,大语言模型正逐步逼近人类级别的认知能力。
|
Python
Python报错ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Python报错ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
2609 1
|
SQL 存储 NoSQL
数据库技术详解:从基础到进阶,掌握数据处理的核心
一、引言 在数字化时代,数据已成为企业的核心资产
|
测试技术 持续交付 UED
探索软件测试的多维面貌:从基础到进阶
在数字化时代的浪潮中,软件测试作为确保产品质量和用户体验的关键步骤,其重要性不言而喻。本文旨在通过深入分析软件测试的各个维度,揭示其在软件开发生命周期中的核心地位。我们将从测试的基本概念出发,逐步展开至测试策略的选择与实施,再探讨自动化测试工具的应用,最后以持续集成的实践为例,展示如何将理论应用于实际工作中,提升测试效率和质量。文章旨在为读者提供一个全面而深入的视角,理解软件测试不仅仅是技术活动,更是一种保障软件项目成功的重要手段。