zoukankan      html  css  js  c++  java
  • hive函数之~reflect函数

    reflect函数可以支持在sql中调用java中的自带函数,秒杀一切udf函数。

    使用java.lang.Math当中的Max求两列中最大值

    创建hive表

    create table test_udf(col1 int,col2 int) row format delimited fields terminated by ',';

    准备数据并加载数据

    cd /export/servers/hivedatas
    vim test_udf

    1,2

    4,3

    6,4

    7,5

    5,6

    加载数据

    hive (hive_explode)> load data local inpath '/export/servers/hivedatas/test_udf' overwrite into table test_udf;

    使用java.lang.Math当中的Max求两列当中的最大值

    hive (hive_explode)> select reflect("java.lang.Math","max",col1,col2) from test_udf;

    不同记录执行不同的java内置函数

    创建hive表

    hive (hive_explode)> create table test_udf2(class_name string,method_name string,col1 int , col2 int) row format delimited fields terminated by ',';

    准备数据

    cd /export/servers/hivedatas
    vim test_udf2

    java.lang.Math,min,1,2

    java.lang.Math,max,2,3

    加载数据

    hive (hive_explode)> load data local inpath '/export/servers/hivedatas/test_udf2' overwrite into table test_udf2;

    执行查询

    hive (hive_explode)> select reflect(class_name,method_name,col1,col2) from test_udf2;

    判断是否为数字

    使用apache commons中的函数,commons下的jar已经包含在hadoop的classpath中,所以可以直接使用。

    使用方式如下:

    select reflect("org.apache.commons.lang.math.NumberUtils","isNumber","123")
  • 相关阅读:
    Coursera机器学习week1 单元测试
    Coursera机器学习week1 笔记
    Apache服务器
    yum软件包安装
    linux察看安装包有那些
    虚拟上怎么挂载镜像
    netstat -altp
    MongoDB——》聚合查询(project、match、limit、skip、unwind、group、sort)
    jdk8流list转Map
    Spring Boot 和 Spring Cloud Feign调用服务及传递参数踩坑记录(转)
  • 原文地址:https://www.cnblogs.com/lojun/p/13251427.html
Copyright © 2011-2022 走看看