大数据入门到精通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 ...
随机推荐
- .Net Core跨平台应用研究-HelloArm(串口篇)
引言 为了验证采用dotnet core技术开发的物联网设备数据采集接入服务应用是否能在高性价比的linux嵌入式平台运行,针对dotnet core应用程序进行嵌入式linux环境的发布部署运行验证 ...
- URLConnection(互联网)
一.urlconnection连接Servlet 1:> URL请求的类别: 分为二类,GET与POST请求.二者的区别在于: ...
- maven私库nexus2.3.0-04迁移升级到nexus-3.16.1-02(异机迁移备份)
环境信息: nexus2.3.0-04安装在32位Windows server 2003系统上 安装位置信息如下: 仓库迁移 Nexus的构件仓库都保存在sonatype-work目录中,nexus2 ...
- CSS3 之 Media(媒体查询器)
1.响应式Media(媒体查询器) (1)<link rel=“stylesheet” media=“screen and (max-width: 600px)” href=“small.css ...
- docker swarm 搭建与服务更新
一,docker swarm 是什么 Docker Swarm.Docker Machine与Docker Compose号称Docker三剑客Docker Swarm 和 Docker Compos ...
- Windows 2012 安装 SQL Server 2012,.Net Framework 3.5安装不成的解决办法
This behavior can also be caused by a system administrator who configures the computer to use Window ...
- 如何在VB.net中建立word文档
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Butt ...
- zk开机自动启动脚本
[Unit] Description=Zookeeper service After=network.target [Service] User=www Group=www SyslogIdentif ...
- IntelliJ IDEA 集成 SVN
在idea中使用subversion提交代码需要使用SVN SVN下载官网:https://tortoisesvn.net/downloads.html 可以根据自己电脑下载相应的版本,如果安装了的需 ...
- 转:强制关闭.net程序
/// <summary> /// 运行DOS命令 /// DOS关闭进程命令(ntsd -c q -p PID )PID为进程的ID /// </summary> /// & ...