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
  • 相关阅读:
    BFS(从数字A变到数字B每次只能换一个数)
    BFS(数字a通过三种操作到数字B)
    dfs+bfs(三种路径问题)
    国际象棋跳马问题
    拓扑排序
    hadoop-hdfs、mapreduce学习随笔
    hive初探2_数据模型
    hive初探_框架组成、简单使用
    Scala学习笔记
    Scala安装
  • 原文地址:https://www.cnblogs.com/sabertobih/p/13587976.html
Copyright © 2011-2022 走看看