hive和spark-sql中 日期和时间相关函数 测试对比

测试版本:

hive 2.3.4      spark 3.1.1  hadoop 2.7.7

1、增加月份

  • add_months(timestamp date, int months)
  • add_months(timestamp date, bigint months)
  • Return type: timestamp
  • usage:add_months(now(),1)

2、增加日期

  • adddate(timestamp startdate, int days),
  • adddate(timestamp startdate, bigint days)
  • Return type: timestamp
  • usage:adddate(now(),1)

3、当前时间戳

  • current_timestamp()和now()等价

4、日期相减

  • datediff(string enddate, string startdate)
  • Return type: int
  • usage:datediff("2018-08-05", "2018-08-03")

5、得到天,得到月份

  • day(string date)
  • Return type: int
  • usage: day("2018-08-05")

6、得到星期英文

  • dayname(string date)
  • Return type: string
  • usage:dayname("2018-08-05") Sunday

7、得到这一天是这周的第几天

  • dayofweek(string date)   1 (Sunday) to 7 (Saturday).
  • Return type: int
  • usage:dayofweek("2018-08-06")

8、加天数和减天数

1)days_add(timestamp startdate, int days)

  • Return type: timestamp
  • usage:days_add(now(),2)

2)、days_sub(timestamp startdate, int days)

  • Return type: timestamp
  • usage:days_sub(now(), 2)

9、格式化日期

  • from_unixtime(bigint unixtime[, string format])
  • Return type: string

注意参数

  • usage:from_unixtime(1392394861,"yyyy-MM-dd");

10、得到小时

  • hour(string date)
  • Return type: int
  • usage:hour("2018-08-06 12:32:54")

11、增加小时 和 减少小时

1)、hours_add(timestamp date, int hours)

  • Return type: timestamp
  • usage:hours_add(now(),2)

2)、hours_sub(timestamp date, int hours)

  • Return type: timestamp
  • usage:hours_sub(now(),2)

12、得到分钟

  • minute(string date)
  • Return type: int
  • usage:minute(now())

13、增加分钟和减少分钟

1)、minutes_add(timestamp date, int minutes)

  • Return type: timestamp
  • usage:minutes_add(now(),2)

2)、minutes_sub(timestamp date, int minutes)

  • Return type: timestamp
  • usage:minutes_sub(now(),2)

14、得到月份

  • month(string date)
  • Return type: int
  • usage:month("2018-08-06 12:32:54")

15、月份相加和减月份

1)、months_add(timestamp date, int months)

  • Return type: timestamp
  • usage:months_add(now(),3)

2)、months_sub(timestamp date, int months)

  • Return type: timestamp
  • months_sub(now(),3)

16、得到秒

  • second(string date)
  • Return type: int

17、秒加 和 秒减

1)、seconds_add(timestamp date, int seconds)

  • Return type: timestamp

2)、seconds_sub(timestamp date, int seconds)

  • Return type: timestamp

18、得到日期

  • to_date(now())

19、得到1970到今秒

  • unix_timestamp(),
  • unix_timestamp(string datetime),
  • unix_timestamp(string datetime, string format),
  • unix_timestamp(timestamp datetime)
  • Return type: bigint

20、得到这周是这年的多少周

  • weekofyear(string date)
  • Return type: int
  • usage:weekofyear("2018-08-06 12:32:54")

21、周加  和 周减

1)、weeks_add(timestamp date, int weeks)

  • Return type: timestamp
  • usage:weeks_add("2018-08-06 12:32:54", 1)

2)、weeks_sub(timestamp date, int weeks)

  • Return type: timestamp
  • usage:weeks_sub("2018-08-06 12:32:54", 1)

22、得到年

  • year(string date)
  • Return type: int

23、年加 和 年减

1)、years_add(timestamp date, int years)

  • Return type: timestamp

2)、years_sub(timestamp date, int years)

  • Return type: timestamp

参考:hive 日期函数 - 文章教程 - 文江博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/135196.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

单链表指定结点的后插 前插操作

指定结点的后插操作 #define NULL 0typedef struct LNode {int data;struct LNode* next; }LNode, * LinkList;//后插操作:在p结点后插入元素e bool InsertNextNode(LNode* p, int e) {if (p NULL)return false;LNode* s (LNode*)malloc(sizeof(LNode));if (s N…

【MySQL】列属性

文章目录 CHAR和VARCHAR插入单行 INSERT INTO插入多行插入分层行 LAST_INSERT_IN()创建表复制 CREAT TABLE AS更新单行 UPDATE...SET更新多行在UPDATES中使用子查询【需着重复习】删除行 DELETE恢复数据库到原始状态 CHAR和VARCHAR CHAR(50):存储文本占5个字符&…

Windows10 安装 Ubuntu(WSL2)

Windows10 安装 Ubuntu(WSL2):因为 Ubuntu(WSL1) 不具备调试功能,所以尽可能安装 Ubuntu(WSL2)。 具体流程如下: 1. 什么是WSL Windows Subsystem for Linux(简称WSL),Windows下的 Linux 子系统&#xff…

面试10000次依然会问的【ThreadLocal】,你还不会?

ThreadLocal简介与基本概念 ThreadLocal,即线程局部变量,是Java语言中用于实现线程数据隔离的一个重要类。这种机制允许在多线程环境中,每个线程都有自己的变量副本,从而使得每个线程都可以独立地改变自己的副本,而不…

【龙芯固件】ACPI——简介

一、 什么是ACPI ACPI是Hewlett-Packard, Intel, Microsoft, Phoenix, 和Toshiba共同制定的一个开放的行业规范。 ACPI由很多表组成,包括:RSDP,SDTH,RSDT,FADT,FACS,DSDT,SSDT&…

【操作系统面试题(32道)与面试Linux命令大全】

文章目录 操作系统面试题引论1.什么是操作系统?2.操作系统主要有哪些功能? 操作系统结构3.什么是内核?4.什么是用户态和内核态?5.用户态和内核态是如何切换的? 进程和线程6.并行和并发有什么区别?7.什么是进…

(2023|CVPR,扩散,主体标识符,先验保存损失)DreamBooth:微调文本到图像的扩散模型以实现主题驱动的生成

DreamBooth: Fine Tuning Text-to-Image Diffusion Models for Subject-Driven Generation 公众号:EDPJ(添加 VX:CV_EDPJ 或直接进 Q 交流群:922230617 获取资料) 目录 0. 摘要 1. 简介 2. 相关工作 3. 方法 3.…

Java 面试题之 Logback 打印日志是如何获取当前方法名称的?

在 Java 中,有四种方法可以获取当前正在执行方法体的方法名称,分别是: 使用 Thread.currentThread().getStackTrace() 方法 使用异常对象的 getStackTrace() 方法 使用匿名内部类的 getClass().getEnclosingMethod() 方法 Java 9 的 Stack…

Clickhouse学习笔记(10)—— 查询优化

单表查询 Prewhere 替代 where prewhere与where相比,在过滤数据的时候会首先读取指定的列数据,来判断数据过滤,等待数据过滤之后再读取 select 声明的列字段来补全其余属性 简单来说就是先过滤再查询,而where过滤是先查询出对应…

[LeetCode周赛复盘] 第 371 场周赛20231112

[LeetCode周赛复盘] 第 371 场周赛20231112 一、本周周赛总结100120. 找出强数对的最大异或值 I1. 题目描述2. 思路分析3. 代码实现 100128. 高访问员工1. 题目描述2. 思路分析3. 代码实现 100117. 最大化数组末位元素的最少操作次数1. 题目描述2. 思路分析3. 代码实现 100124…

Linux tail命令:显示文件结尾的内容

tail 命令和 head 命令正好相反,它用来查看文件末尾的数据,其基本格式如下: [rootlocalhost ~]# tail [选项] 文件名 此命令常用的选项及含义 【例 1】查看 /etc/passwd 文件最后 3 行的数据内容。 [rootlocalhost ~]# tail -n 3 /etc/passwd…

全域旅游“一机游”智慧旅游平台解决方案:PPT全文48页,附下载

关键词:智慧文旅解决方案,智慧旅游解决方案,智慧旅游平台建设方案,智慧文旅综合运营平台,智慧文旅建设方案 一、智慧文旅一机游定义 智慧文旅一机游是一种新型的旅游方式,它通过智能化的设备和系统&#…

(一)正点原子I.MX6ULL kernel6.1移植

一、概述 学完了正点原子的I.MX6ULL移植,正点原子的教程是基于Ubuntu18,使用的是4.1.15的内核,很多年前的了。NXP官方也发布了新的6.1的内核,以及2022.04的uboot。 本文分享一下基于Ubuntu22.04(6.2.0-36-generic&…

发送失败的RocktMQ消息,你遇到过吗?

背景 需要通过flink同时向测试和线上的RocketMQ中写入数据 现象 在程序中分别创建了两个MqProducer,设置了不同的nameServerAddr,分别调用不同的producer向不同环境发消息,返回发送成功,但是在线上MQ中却查不到数据&#xff0…

分布式理论基础:CAP定理

什么是CAP CAP原则又称CAP定理,指的是在一个分布式系统中,Consistency(一致性)、 Availability(可用性)、Partition tolerance(分区容错性)这三个基本需求,最多只能同时…

【学习辅助】Axure手机时间管理APP原型,告别手机控高保真模板

作品概况 页面数量:共 30 页 兼容软件:Axure RP 9/10,不支持低版本 应用领域:时间管理、系统工具 作品申明:页面内容仅用于功能演示,无实际功能 作品特色 本品为「手机时间管理」APP原型,…

RK3568平台 在alsa框架中添加音频功放芯片

一.alsa框架概述 ALSA,全称是Advanced Linux Sound Architecture,是Linux中提供声音设备驱动的内核组件,应用可以通过ALSA接口实现音频播放、录音、设备通路控制、音量控制、通话等功能。 在 Linux 内核设备驱动层,ALSA 提供了 …

焕新古文化传承之路,AI为古彝文识别赋能

目录 1 古彝文与古典保护 2 古文识别的挑战 2.1 西文与汉文OCR 2.2 古彝文识别难点 3 合合信息:古彝文保护新思路 3.1 图像矫正 3.2 图像增强 3.3 语义理解 3.4 工程技巧 4 总结 1 古彝文与古典保护 彝文指的是云南、贵州、四川等地的彝族人使用的文字&am…

AI小镇Generative Agents: Interactive Simulacra of Human Behavior

文章目录 1 Introduction2 Related Works2.1 Human-AI Interaction2.2 Belivable Proxies for Human Behavior2.3 Large Language Model and Human Behavior 3 Generative agent behavior and interaction(行为与交互)3.1 Agent Avatar and Communicatio…
最新文章