大数据入门到精通15--hive 对 date类型的处理
一。基础日期处理
//date 日期处理
select current_date;
select current_timestamp;
//to_date(time) ;to_date(string)
select to_date(current_timestamp);
select to_date(rental_date) from rental limit 10;
month(date/time)
year(date/time)
day(date/time)
second(time)
minute(time)
hour(time)
select hour("22:32:34.0");
select hour(rental_date),count(hour(rental_date)) counts from rental group by hour(rental_date) order by counts;
//注意order by的字段必须要有名字或者别名
unix_timestamp(timestamp)
from_unixtime(unixtime)
//两种时间格式互转
to_utc_timestamp(timestamp,"EST")
from_utc_timestamp(timestamp,"EST")
//于标准时间之间的互转
select unix_timestamp();
select unix_timestamp(current_timestamp);
select from_unixtime(unix_timestamp(current_timestamp));
select from_utc_timestamp(to_utc_timestamp(current_timestamp,"EST"),"EST"),current_timestamp;
二、高级日期时间格式的处理
//高级的日期功能
datediff(time,time)给出天数差
select datediff("2018-02-02 21:43:32.0","2017-02-02 21:43:32.0");
add_months(time,num)
date_add(time,num)
select add_months(current_timestamp,2);
select date_add(current_timestamp,2);
hive> select add_months(current_timestamp,2);
OK
2019-02-12
Time taken: 0.126 seconds, Fetched: 1 row(s)
hive> select date_add(current_timestamp,2);
OK
2018-12-14
Time taken: 0.123 seconds, Fetched: 1 row(s)
hive>
//日期格式化
date_format(time,"YYYYMMDDHHmmss")
select date_format(current_timestamp,"YYYYMMDDHHmmss")
//支持EE EEEE格式来表示星期
大数据入门到精通15--hive 对 date类型的处理的更多相关文章
- 大数据入门到精通19--mysql 数据导入到hive数据中
一.正常按照数据库和表导入 \\前面介绍了通过底层文件得形式导入到hive的表中,或者直接导入到hdfs中,\\现在介绍通过hive的database和table命令来从上层操作.sqoop impo ...
- 大数据入门到精通18--sqoop 导入关系库到hdfs中和hive表中
一,选择数据库,这里使用标准mysql sakila数据库 mysql -u root -D sakila -p 二.首先尝试把表中的数据导入到hdfs文件中,这样后续就可以使用spark来dataf ...
- 大数据入门到精通12--spark dataframe 注册成hive 的临时表
一.获得最初的数据并形成dataframe val ny= sc.textFile("data/new_york/")val header=ny.firstval filterNY ...
- 大数据入门到精通16--hive 的条件语句和聚合函数
一.条件表达 case when ... then when .... then ... when ... then ...end select film_id,rpad(title,20," ...
- 大数据入门到精通13--为后续和MySQL数据库准备
We will be using the sakila database extensively inside the rest of the course and it would be great ...
- 大数据入门到精通2--spark rdd 获得数据的三种方法
通过hdfs或者spark用户登录操作系统,执行spark-shell spark-shell 也可以带参数,这样就覆盖了默认得参数 spark-shell --master yarn --num-e ...
- 大数据入门到精通14--hive 对 字符串的操作
一.基本操作 concat(string,string,string)concat_ws(string,string,string)select customer_id,concat_ws(" ...
- 大数据入门到精通11-spark dataframe 基础操作
// dataframe is the topic 一.获得基础数据.先通过rdd的方式获得数据 val ny= sc.textFile("data/new_york/")val ...
- 大数据入门到精通10--spark rdd groupbykey的使用
//groupbykey 一.准备数据val flights=sc.textFile("data/Flights/flights.csv")val sampleFlights=sc ...
随机推荐
- fatal error: No such file or directory
在fase_ws中编译ground_car包,遇如下报错: /home/gordon/fase_ws/src/fsae/ground_car/plugins/gazebo_ros_block_lase ...
- Stripes视图框架与Struts2之间的比较
https://blog.csdn.net/boonya/article/details/14227149 Stripes视图框架与Struts2的行为很相似,所以在这里做一个简要的对比,发现它们的优 ...
- Mysql中判断一个点是否落在多边形内
关于地理空间数据,经常需要处理两个空间数据的关联关系.有很多种方法可以处理,通过编写程序算法,或者是调用数据库中对应的function.在mysql数据库中,https://dev.mysql.com ...
- ELK + Filebeat 日志分析系统
ELK + Filebeat 日志分析系统 架构图 环境 OS:CentOS 7.4 Filebeat: 6.3.2 Logstash: 6.3.2 Elasticsearch 6.3.2 Kiban ...
- YARN简述
YARN(Yet Another Resource Negotiator)是Hadoop的集群资源管理系统.YARN提供请求和使用集群资源的API,但这些API很少直接用于用户代码.相反,用户代码中用 ...
- 前端-JavaScript1-7——JavaScript之数学运算符
---恢复内容开始--- 运算符叫做operator,也可以叫做操作符.运算符有很多种,一元运算符.二元运算符:数学运算符.逻辑运算符……我们今天先学习数学运算符,比较简单 + 加法 - ...
- nvidia驱动自动更新版本后问题解决 -- failed to initialize nvml: driver/library version mismatch
因为必须关闭桌面窗口, 建议另外一台电脑ssh连接操作 1. 卸载旧版本并关闭图形界面 sudo apt-get remove --purge nvidia-\* sudo service light ...
- C++调用JS函数
1 调用方法 https://blog.csdn.net/donglinshengan/article/details/29828103 https://blog.csdn.net/sunmz_wjx ...
- cesium 拾取模型表面的坐标
scene = viewer.scene;var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);handler.setInput ...
- linux服务器后台运行服务
linux 后台运行一个服务 难免会遇到在Linux,后台执行任务.下面,总结了一下关闭窗口任然在后台执行的方法,例如 #执行一个打包命令 tar czf /data/backup.tgz /data ...