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")
  • 相关阅读:
    Delphi数据库处理
    cxgrid的FINDPANEL编程
    LESS简介
    LESS速查
    $(window).load(function() {})和$(document).ready(function(){})的区别
    CSS中单位px和em,rem的区别
    父元素与子元素之间的margin-top问题
    CSS垂直居中精华总结
    Font Awesome使用指南
    Sublime3安装过程及常用插件安装及常用快捷键
  • 原文地址:https://www.cnblogs.com/lojun/p/13251427.html
Copyright © 2011-2022 走看看