zoukankan      html  css  js  c++  java
  • hive 中简单的udf函数编写

    1.注册函数,使用using jar方式在hdfs上引用udf库。
    $hive>create function formattime as 'com.bigdata.udf.FormatTimeUDF' using jar 'hdfs://hadoop01/app/app-logs-hive-1.0-SNAPSHOT.jar';2.注销函数,只需要删除mysql的hive数据记录即可。
    delete from func_ru ;
    delete from funcs ;
    show funcyions;
    desc formatted function substring;



    2.udf函数获取天开始一些简单方法
    @Description(name = "udf_getdaybegin", value = "getdaybegin", extended = "getdaybegin() ; " + " getdaybegin(2) " + " getdaybegin('2017/06/29 01:02:03') " + " getdaybegin('2017/06/29 01:02:03',2) " + " getdaybegin(date_obj) " + " getdaybegin(date_obj,2)") public class DayBeginUDF extends UDF { /** * 计算现在的起始时刻(毫秒数) */ public long evaluate() throws ParseException { return evaluate(new Date()); } /** * 指定天偏移量 */ public long evaluate(int offset) throws ParseException { return evaluate(DateUtil.getDayBeginTime(new Date(), offset)); } /** * 计算某天的开始时刻(毫秒数) */ public long evaluate(Date d) throws ParseException { return DateUtil.getDayBeginTime(d).getTime(); } /** * 计算某天的开始时刻(毫秒数) */ public long evaluate(Date d, int offset) throws ParseException { return DateUtil.getDayBeginTime(d, offset).getTime(); } /** * 计算某天的起始时刻(毫秒数) */ public long evaluate(String dateStr) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date d = sdf.parse(dateStr); return evaluate(d); } /** * 计算某天的起始时刻(毫秒数) */ public long evaluate(String dateStr, int offset) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date d = sdf.parse(dateStr); return DateUtil.getDayBeginTime(d, offset).getTime(); } /** * 计算某天的起始时刻(毫秒数) */ public long evaluate(String dateStr, String fmt) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(fmt); Date d = sdf.parse(dateStr); return DateUtil.getDayBeginTime(d).getTime(); } /** * 计算某天的起始时刻(毫秒数) */ public long evaluate(String dateStr, String fmt, int offset) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(fmt); Date d = sdf.parse(dateStr); return DateUtil.getDayBeginTime(d, offset).getTime(); } }
  • 相关阅读:
    vscode snippet
    OpenGL Type
    [转] fio参数详解
    [转] openchannel SSD( OCSSD)
    [转]linux内存管理
    proc/meminfo && hugepage
    [转] 从free到 page cache
    [转]linux网络协议栈(1)——链路层
    [转]linux 网络协议栈(1)——网络设备
    [转]linux网络协议栈(1)——socket buffer
  • 原文地址:https://www.cnblogs.com/hejunhong/p/10321022.html
Copyright © 2011-2022 走看看