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() ;\r\n"
+ " getdaybegin(2) \r\n"
+ " getdaybegin('2017/06/29 01:02:03') \r\n"
+ " getdaybegin('2017/06/29 01:02:03',2) \r\n"
+ " getdaybegin(date_obj) \r\n"
+ " 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();
}
}

hive 中简单的udf函数编写的更多相关文章

  1. Hive中如何添加自定义UDF函数以及oozie中使用hive的自定义函数

    操作步骤: 1. 修改.hiverc文件 在hive的conf文件夹下面,如果没有.hiverc文件,手工自己创建一个. 参照如下格式添加: add jar /usr/local/hive/exter ...

  2. Hive扩展功能(三)--使用UDF函数将Hive中的数据插入MySQL中

    软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...

  3. hive中简单介绍分区表

    所介绍内容基本上是翻译官方文档,比较肤浅,如有错误,请指正! hive中创建分区表没有什么复杂的分区类型(范围分区.列表分区.hash分区.混合分区等).分区列也不是表中的一个实际的字段,而是一个或者 ...

  4. hive中简单介绍分区表(partition table)——动态分区(dynamic partition)、静态分区(static partition)

    一.基本概念 hive中分区表分为:范围分区.列表分区.hash分区.混合分区等. 分区列:分区列不是表中的一个实际的字段,而是一个或者多个伪列.翻译一下是:“在表的数据文件中实际上并不保存分区列的信 ...

  5. 在JS中简单实现Formatter函数

    JS原生并没有提供方便使用的Formatter函数,用字符拼接的方式看起来混乱难读,而且使用起来很不方便.个人感觉C#里提供的语法比较好用,如: String.Format("Welcome ...

  6. hive中的日期转换函数

    1.unix时间戳转时间函数   语法: from_unixtime(bigintunixtime[, string format]) 返回值: string   说明: 转化UNIX时间戳(从197 ...

  7. 如何编写自定义hive UDF函数

    Hive可以允许用户编写自己定义的函数UDF,来在查询中使用.Hive中有3种UDF: UDF:操作单个数据行,产生单个数据行: UDAF:操作多个数据行,产生一个数据行. UDTF:操作一个数据行, ...

  8. Hive中自定义函数

    Hive的自定义的函数的步骤: 1°.自定义UDF extends org.apache.hadoop.hive.ql.exec.UDF 2°.需要实现evaluate函数,evaluate函数支持重 ...

  9. UDF、UDAF、UDTF函数编写

    一.UDF函数编写 1.步骤 1.继承UDF类 2.重写evalute方法 .继承GenericUDF .实现initialize.evaluate.getDisplayString方法 2.案例 实 ...

随机推荐

  1. [py]初始化dict结构和json.dump使用

    1.json.dump使用 http://python3-cookbook.readthedocs.io/zh_CN/latest/c06/p02_read-write_json_data.html ...

  2. 【Python】-NO.96.Note.2.Python -【Python 基础】

    1.0.0 Summary Tittle:[Python]-NO.95.Note.1.Python -[Python 老男孩 基础]- Style:Python Series:Python Since ...

  3. fasttext与Linear SVC 分类测试结果

    任务:分类出优质问题与非优质问题.任务背景:用户实际与智能客服交互的时候,如果只做阈值限制,在相似问题匹配的时候(由于词的重复),依然会匹配出部分结果.如:问题为 "设置好了?", ...

  4. MyBatis SpringMVC映射配置注意

    applicationContext.xml中要配置 <!-- MyBatis 的 sqlSessionFactory --> <bean id="sqlSessionFa ...

  5. [LeetCode] 661. Image Smoother_Easy

    Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...

  6. CentOS6.5安装Elasticsearch5.3.0

    1. 首页到官方网站下载最新安装包 https://www.elastic.co/downloads/elasticsearch elasticsearch-5.3.0.tar.gz 2. 将软件包上 ...

  7. fullpage插件在移动端弹出键盘页面特殊处理

    fullpage插件大家都很熟悉 jquery一款全屏上下滑动的插件. 最近做公司一个活动移动端使用fullpage插件填写input的时候遇见一个问题,手机自带的键盘弹出的时候会把页面顶出去,页面错 ...

  8. Express web框架 upload file

    哈哈,敢开源,还是要有两把刷子的啊 今天,看看node.js 的web框架 Express的实际应用 //demo1 upload file <html><head><t ...

  9. JS基础篇-- body.scrollTop与documentElement.scrollTop

    获取当前页面滚动条纵坐标的位置:document.body.scrollTop与document.documentElement.scrollTop 获取当前页面滚动条横坐标的位置:document. ...

  10. Cocos Creator 计时器的延时循环试用方法

    *****计时器的一些运用***** //计算1次的计时器,2秒后执行 this.scheduleOnce(function(){ this.doSomething(); },2); //每隔5秒执行 ...