zoukankan      html  css  js  c++  java
  • hive 之用户自定义函数

    一、quickstart 项目

    pom中:

    <repositories>
        <repository>
          <id>cloudera</id>
          <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
        </repository>
      </repositories>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <hive.version>1.2.1</hive.version>
        <hadoop.version>2.7.3</hadoop.version>
        <jdk.version>0.11.0.0-cp1</jdk.version>
        <junit.version>4.12</junit.version>
        <mvnshade.version>2.4.1</mvnshade.version>
        <confluent.maven.repo>http://packages.confluent.io/maven/</confluent.maven.repo>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>${junit.version}</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.hive</groupId>
          <artifactId>hive-exec</artifactId>
          <version>${hive.version}</version>
        </dependency>
        <dependency>
          <groupId>org.apache.hadoop</groupId>
          <artifactId>hadoop-common</artifactId>
          <version>${hadoop.version}</version>
        </dependency>
      </dependencies>

    二、目录

    package cn.kb08.udxf.udf;
    public class InString extends UDF {
    
    // 一定是evaluate方法,否则不识别
    public boolean evaluate(String str,String subStr){ return null != str && null != subStr && str.length()>0 && subStr.length()<=str.length() && str.indexOf(subStr)>=0; } }

    三、发布

    1)maven-package打成jar包(如果用普通方式,需要增加个文件)
    2)beeline中:
    add/delete jar /root/kb08/hive/hiveudxf-1.0-SNAPSHOT.jar
    create/drop temporary function within as 'cn.kb08.udxf.udf.InString'
    >>> 临时函数,会话结束就没了
    3)show functions看看有没有within函数
    4)select within('123123','123') --->  true
  • 相关阅读:
    CentOS随笔
    CentOS随笔
    CentOS随笔
    CentOS随笔
    产品从生到死的N宗罪
    即将结束的2015。
    Mvvm
    android 热补丁修复框架
    反编译APK
    关于短视频
  • 原文地址:https://www.cnblogs.com/sabertobih/p/13587976.html
Copyright © 2011-2022 走看看