复合类型构建操作

1. Map类型构建: map

语法: map (key1, value1, key2, value2, …)

说明:根据输入的key和value对构建map类型

举例:

hive> Create table lxw_test as select map('100','tom','200','mary') as t from lxw_dual;

hive> describe lxw_test;

t       map<string,string>

hive> select t from lxw_test;

{"100":"tom","200":"mary"}

2. Struct类型构建: struct

语法: struct(val1, val2, val3, …)

说明:根据输入的参数构建结构体struct类型

举例:

hive> create table lxw_test as select struct('tom','mary','tim') as t from lxw_dual;

hive> describe lxw_test;

t       struct<col1:string,col2:string,col3:string>

hive> select t from lxw_test;

{"col1":"tom","col2":"mary","col3":"tim"}

3. array类型构建: array

语法: array(val1, val2, …)

说明:根据输入的参数构建数组array类型

举例:

hive> create table lxw_test as select array("tom","mary","tim") as t from lxw_dual;

hive> describe lxw_test;

t       array<string>

hive> select t from lxw_test;

["tom","mary","tim"]

十、复杂类型访问操作

1. array类型访问: A[n]

语法: A[n]

操作类型: A为array类型,n为int类型

说明:返回数组A中的第n个变量值。数组的起始下标为0。比如,A是个值为['foo', 'bar']的数组类型,那么A[0]将返回'foo',而A[1]将返回'bar'

举例:

hive> create table lxw_test as select array("tom","mary","tim") as t from lxw_dual;

hive> select t[0],t[1],t[2] from lxw_test;

tom     mary    tim

2. map类型访问: M[key]

语法: M[key]

操作类型: M为map类型,key为map中的key值

说明:返回map类型M中,key值为指定值的value值。比如,M是值为{'f' -> 'foo', 'b' -> 'bar', 'all' -> 'foobar'}的map类型,那么M['all']将会返回'foobar'

举例:

hive> Create table lxw_test as select map('100','tom','200','mary') as t from lxw_dual;

hive> select t['200'],t['100'] from lxw_test;

mary    tom

3. struct类型访问: S.x

语法: S.x

操作类型: S为struct类型

说明:返回结构体S中的x字段。比如,对于结构体struct foobar {int foo, int bar},foobar.foo返回结构体中的foo字段

举例:

hive> create table lxw_test as select struct('tom','mary','tim') as t from lxw_dual;

hive> describe lxw_test;

t       struct<col1:string,col2:string,col3:string>

hive> select t.col1,t.col3 from lxw_test;

tom     tim

十一、复杂类型长度统计函数

1.    Map类型长度函数: size(Map<K.V>)

语法: size(Map<K.V>)

返回值: int

说明: 返回map类型的长度

举例:

hive> select size(map('100','tom','101','mary')) from lxw_dual;

2

2.    array类型长度函数: size(Array<T>)

语法: size(Array<T>)

返回值: int

说明: 返回array类型的长度

举例:

hive> select size(array('100','101','102','103')) from lxw_dual;

4

3.    类型转换函数

类型转换函数: cast

语法: cast(expr as <type>)

返回值: Expected "=" to follow "type"

说明: 返回array类型的长度

举例:

hive> select cast(1 as bigint) from lxw_dual;

1

4. 其他

cast 函数:
类型转换函数,cast(kbcount as int);

case when:
条件判断,case when kbcount is not null and cast(kbcount as int) >= cast(patch_count as int) then '1' else '0' end as isinstalled ;
语法:方法1
(
case sex
when '1' then '男'
when '2' then '女'
else '未知'
end
) as 性别

方法2
case
when sex='1' then '男'
when sex='2' then '女'
else '未知'
end as 性别

from_unixtime:将unix时间戳转化为制定格式的时间
from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') as xdsp_last_update_time

lcase() :将字段的值转换为小写
lcase(t.info_iot_name)

hive collect_set: 可以得到分组后,其他合并元素的制定位置的值作为去重后的值。

表明:user
id , name, url
1 shao www
1 shao1 www1
2 zhi www
2 zhi1 www.ee
2 zhi2 www.2323
3 qi www.eere
3 qi2 www.urr

想要得到:
id , name, url
1 shao www
2 zhi www
3 qi www.eere

sql实现:方法1
select id ,collect_set(name)[0],collect_set(url)[0]
from user
group by id;

方法2:
select id ,max(name),max(url)
from user
group by id;

字符串max:字符串按照字母A-Z,越往后值越大
汉字按照全拼字母排,第一个字母相同则看第二个
concat() : 将两个或者多个字符串连接起来,如果有任何一个参数为null,则返回值为null
a.os_version like concat('%','2012r2','%')
concat_ws(): 以第一个参数为分隔符,将其他参数连起来
concat_ws('.',os_version_main,os_version_sp,os_version_bit,os_version_sub)

hive常用函数五的更多相关文章

  1. Hive常用函数的使用

    Hive常用函数的使用 文章作者:foochane  原文链接:https://foochane.cn/article/2019062501.html 1 基本介绍 1.1 HIVE简单介绍 Hive ...

  2. hive常用函数 wordCount--Hive窗口函数1.1.1 聚合开窗函数聚合开窗函数实战

    第三天笔记 第三天笔记 SQL练习Hive 常用函数关系运算数值计算条件函数日期函数重点!!!字符串函数Hive 中的wordCount1.1 Hive窗口函数1.1.1 聚合开窗函数聚合开窗函数实战 ...

  3. Hive常用函数

    字符串函数 字符串长度函数:length 语法: length(string A) 返回值: int 说明:返回字符串A的长度 举例: hive> select length(‘abcedfg’ ...

  4. Hive 常用函数

    参考地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1. parse_url(url, partToExt ...

  5. orcale和hive常用函数对照表(?代表未证实)

    函数分类 oracle hive 说明 字符函数 upper('coolszy') upper(string A) ucase(string A) 将文本字符串转换成字母全部大写形式 lower('K ...

  6. Hive 常用函数汇总

    Hive内部提供了很多函数给开发者使用,包括数学函数,类型转换函数,条件函数,字符函数,聚合函数,表生成函数等等,这些函数都统称为内置函数. 目录 数学函数 集合函数 类型转换函数 日期函数 条件函数 ...

  7. hive常用函数六

    cast 函数: 类型转换函数,cast(kbcount as int); case when: 条件判断,case when kbcount is not null and cast(kbcount ...

  8. hive常用函数四

    字符串函数 1. 字符串长度函数:length 语法: length(string A) 返回值: int 说明:返回字符串A的长度 举例: hive> select length('abced ...

  9. hive常用函数三

    日期函数 1. UNIX时间戳转日期函数: from_unixtime 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string ...

随机推荐

  1. [Alg] 文本匹配-多模匹配-AC自动机

    1. 简介 AC自动机是一种多模匹配的文本匹配算法. 如果采用naive的方法,即依次比较文本串s中是否包含模式串p1, p2,...非常耗时.考虑到这些模式串中可能具有相同子串,可以利用已经比较过的 ...

  2. ajax上传文件,通过FromData把数据传给后端

    前端代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  3. git版本控制系统小白教程(上)

    前言:本文主要介绍git版本控制系统的一些基础使用,适合小白入门,因为内容较多,会分为两部分进行分享. Git介绍 ​ Git是目前世界上最先进的分布式版本控制系统.并且它是一个开源的分布式版本控制系 ...

  4. MyBatis框架——快速入门

    主流的ORM框架(帮助开发者实现数据持久化工作的框架): 1.MyBatis: 半自动化ORM框架,半自动:指框架只完成一部分功能,剩下的工作仍需开发者手动完成. MyBatis 框架没有实现 POJ ...

  5. Error: java.net.ConnectException: Call From tuge1/192.168.40.100 to tuge2:8032 failed on connection exception

    先看解决方案,再看唠嗑,唠嗑可以忽略. 解决方案: 使用start yarn.sh启动yarn就可以了. 唠嗑: 今天学习Spark基于Yarn部署.然后总以为Yarn是让Spark启动的,提交程序的 ...

  6. VUE axios请求 封装 get post Http

    创建httpService.js 文件 import axios from 'axios'; import { Loading , Message } from 'element-ui'; impor ...

  7. hdu2544SPFA板题

    SPFA顾名思义就是更快的最短路算法,是Bellman ford算法的优化,SPFA的平均复杂度大约是O(K*|E|),在一般情况下K大约是小于等于2的数,但是总有人对你心怀不轨,构造一组SPFA最坏 ...

  8. Java第十三周实验作业

    实验十三  图形界面事件处理技术 实验时间 2018-11-22 1.实验目的与要求 (1) 掌握事件处理的基本原理,理解其用途: 事件源:能够产生事件的对象都可以成为事件源,如文本框.按钮等,一个事 ...

  9. 题解 P1278 【单词游戏】

    前言 首先,看到这道题目,我首先想到的是暴搜,通过\(vector\)来搞,代码也是很短的. 这里用了一个类似于分治的思想 把一个大问题转化为小问题 先枚举第一个单词,之后把能拼接在它后面的单词都一个 ...

  10. 彻底明白equals和hashCode

    equals和hashCode方法 equals 我们知道equals是用来比较两个对象是否相等的,比如我们常用的String.equals方法 @Test public void test() { ...