Hive部分函数解析

Hive里的exists ,in ,not exists ,not in 相关函数

表数据准备:

1.选择指定数据库 eg:  use bg_database1;

2. 创建表

drop table demo0919 ;
create table demo0919(
name string
,age int
,sex int
) row format delimited fields terminated by '\001';

3.插入表数据

insert overwrite table demo0919 values('zs',18,1);
insert into table demo0919 values('ls',18,1);
insert into table demo0919 values('nisa',19,0);
insert into table demo0919 values('rina',22,0);
insert into table demo0919 values('zhaoxi',25,1);

 

4. 根据原表 demo0919 再创建一张表 demo0919_1,用于比对数据。

create table demo0919_1 as select *from demo0919;

  

5.查看表数据

select *from demo0919;

函数测试

in:

in的简单使用(ok,支持):

select name,age,sex from demo0919 where age in (18,22);

in 里面嵌套子查询 (error ,不支持)

select name,age,sex from demo0919 where age in (select a.age from demo0919_1 a );

not in :

not in 的简单使用(ok, 支持)

select name,age,sex from demo0919 where age not in (18,22);

not in 里面嵌套子查询 (error ,不支持)

select name,age,sex from demo0919 where age not in (select a.age from demo0919_1 a);

exists:

exists 基本使用(ok)

select name,age,sex from demo0919 where exists (select 1 from demo0919_1 a where a.age=18 and demo0919.name = a.name);

exists子查询里面使用了 外表demo0919中的字段 不等于(> , < , >= , <= , <>) 子查询表中的字段(error 不支持)

select name,age,sex from demo0919 where exists (select 1 from demo0919_1 a where a.age>demo0919.age and demo0919.name = a.name);

处理方案:

根据此段我们可以借助left outer join,left semi join 来实现类似功能 前者允许右表的字段在select或where子句中引用,而后者不允许。

(left semi join :需要注意 使用left semi join时 右侧的表不能被使用,只能在on后面作为条件筛选)

select d.name,d.age,d.sex from demo0919 d left outer join demo0919_1 a on d.name = a.name  where a.age>d.age;

exists子查询里面未使用 外表demo0919中的字段 不等于(> , < , >= , <= , <>) 子查询表中的字段(ok 支持)

select name,age,sex from demo0919 where exists (select 1 from demo0919_1 a where a.age>18 and demo0919.name = a.name);

not exists 与 exist雷同。

Hive数据类型转换函数:

daycount string;    daycount表示耗时数据信息,原来定义为string类型

cast(daycount AS FLOAT)  将string类型数据转换为FLOAT类型

Hive日期类型转换函数:

unix_timestamp(countdate)  :将日期转换为时间戳, countdate为日期字段

from_unixtime(unix_timestamp(countdate),'yyyy-MM-dd HH:mm:ss')  :格式化当前时间

Hive的group by :(这里是因为我们在使用group by时用到了带时分秒的日期字段,hive精确到了毫秒级别,mysql中精确到秒,带有日期字段的数据一起dsitinct 或 group by的时候 数据就会有差异)

因为hive保留了 毫秒位数据,故结果数据会比mysql多

例如: 2019-09-19 12:12:12.1     2019-09-19 12:12:12.2

在hive里面 distinct后这是两个不同的日期 2019-09-19 12:12:12.1     2019-09-19 12:12:12.2

在mysql里面 distinct后 这就是相同的日期了  2019-09-19 12:12:12

Hive部分函数解析的更多相关文章

  1. [Hive]HiveSQL解析原理

    Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...

  2. hive中解析json数组

    -- hive中解析json数组 select t1.status ,substr(ss.col,,) as col ,t3.evcId ,t3.evcLicense ,t3.evcAddress , ...

  3. hive源代码解析之一hive主函数入口

    hive其实做的就是解析一条sql然后形成到mapreduce任务,就是一个代码解释器.hive源代码本身就可以分为ql/metasotre/service/serde 这几块:其中 对于Hive来说 ...

  4. Hive基本命令解析

    1. Hive的分区作用 命令:创建分区 create table t_sz_part(id int, name string) partitioned by (country string) row ...

  5. hive 元数据解析

    在使用Hive进行开发时,我们往往需要获得一个已存在hive表的建表语句(DDL),然而hive本身并没有提供这样一个工具. 要想还原建表DDL就必须从元数据入手,我们知道,hive的元数据并不存放在 ...

  6. Hive Hadoop 解析 orc 文件

    解析 orc 格式 为 json 格式: ./hive --orcfiledump -d <hdfs-location-of-orc-file> 把解析的 json 写入 到文件 ./hi ...

  7. 如何在 Apache Hive 中解析 Json 数组

    我们都知道,Hive 内部提供了大量的内置函数用于处理各种类型的需求,参见官方文档:Hive Operators and User-Defined Functions (UDFs).我们从这些内置的 ...

  8. hive sql 解析json

    在hive中会有很多数据是用json格式来存储的,而我们用数据的时候又必须要将json格式的数据解析成为正常的数据,今天我们就来聊聊hive中是如何解析json数据的. 下面这张表就是json格式的表 ...

  9. Saiku部分函数解析(八)

    Saiku函数解析 1.   now()  :  获取当前日期 直接使用即可 2. IIF(logic_exp, string, string): IIF判断,logic_exp是逻辑表达式,结果为t ...

随机推荐

  1. 为什么HashMap的加载因子是0.75?

    说在前面 ​ 在HashMap中,默认创建的数组长度是16,也就是哈希桶个数为16,当添加key-value的时候,会先计算出他们的哈希值(h = hash),然后用return h & (l ...

  2. 如何禁止chrome浏览器http自动转成https

    Chrome 浏览器 地址栏中输入 chrome://net-internals/#hsts 在 Delete domain security policies 中输入项目的域名,并 Delete 删 ...

  3. 【ZooKeeper系列】2.用Java实现ZooKeeper API的调用

    温馨提示:在这里我再次提个小要求,希望大家能习惯看官方文档,文档虽然是英文但用词都比较简单,基本都能看懂文档表达的意思.授之以鱼不如授之以渔的道理相信大家都明白,也希望通过猿人谷的这个ZooKeepe ...

  4. ES6中export default与export的区别

    1.export default 和export都可以用于导出常量,函数,文件,模块等: 2.可以在模块中通过import+(常量 | 函数 | 文件 | 模块)名的方式,将其导入,以便能够对其进行使 ...

  5. 使用for语句输出1-100之间的所有偶数

    使用for语句输出1-100之间的所有偶数 for i in range(1,101): if i%2==0: print(i) 使用while语句输出1-100之间能够被3整除的数字 j=1 whi ...

  6. django基础之day09,手机号校验的规则和代码编写

    通过re模块实现手机号码校验的脚本--json老师 import re 通过re模块实现手机号码校验的脚本--json老师 def mobile_validate(value): mobile_re ...

  7. 数组知识总结(js)

    js数组知识注意点: 声明空数组时,和c语言中的不同 js c var arr=[ ] //合法,声明一个空数组,数组长度为0; int a[];//错误因为在c中声明一个数组不仅要指定类型还要指定数 ...

  8. vue-cli4.0脚手架安装

    10月16日,官方发布消息称Vue-cli 4.0正式版发布,并且强烈建议升级;小编也是刚刚安装了最新版本的脚手架看看更新了什么 安装和vue-cli3.0的是一模一样的,对比了一下3.0的脚手架,除 ...

  9. Android 中 MessageQueue 的 nativePollOnce

    Android SDK 中的事件循环已经是一个老生常谈的问题了, 像 Handler Looper MessageQueue 这几个类也是被大家研究透彻了. 但是再回头看以前自己的分析, 总感觉差点什 ...

  10. iOS编译自动升级版本号脚本

    版权申明: 本文原创首发于以下网站,您可以自由转载,但必须加入完整的版权声明 博客园:https://www.cnblogs.com/MogooStudio/ csdn博客:https://blog. ...