hive支持sql大全(9-11:复合类型构建操作/复杂类型访问操作/复杂类型长度统计函数)
来源:互联网 发布:知乎什么时候成立的 编辑:程序博客网 时间:2024/05/19 05:30
九、复合类型构建操作1. Map类型构建: map
2. Struct类型构建: struct
3. array类型构建: array
十、复杂类型访问操作1. array类型访问: A[n]
2. map类型访问: M[key]
3. struct类型访问: S.x
十一、复杂类型长度统计函数1. Map类型长度函数: size(Map<K.V>)
2. array类型长度函数: size(Array<T>)
3. 类型转换函数
语法: 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 selectarray("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 selectarray("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 selectmap('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;
阅读全文
0 0
- hive支持sql大全(9-11:复合类型构建操作/复杂类型访问操作/复杂类型长度统计函数)
- HIVE UDF整理:复杂类型长度统计函数,类型转换函数,日期函数
- Hive常用函数大全(一)(关系/数学/逻辑/数值/日期/条件/字符串/集合统计/复杂类型)
- hive中的复杂类型使用
- hive udaf 返回复杂类型
- STL set 复杂类型的操作
- mybatis association 复杂类型联合操作
- mybatis association 复杂类型联合操作
- mybatis association 复杂类型联合操作
- hive基本类型和复杂类型
- 复杂类型
- Hive的复杂数据类型和时间类型
- Ibatis对复杂类型的保存或查询操作
- EF支持复杂类型的实现
- Hive之复合类型
- 复杂的变量类型
- Struts2复杂类型
- 派生复杂类型
- BootStrap FileInput 插件实现多文件上传前端功能
- spring面向切面编程
- linux记录锁(范围锁)
- HDU 6047 Maximum Sequence 贪心 区间最值
- Druid 连接池 JDBCUtils 工具类的使用
- hive支持sql大全(9-11:复合类型构建操作/复杂类型访问操作/复杂类型长度统计函数)
- django 多并发,多线程。
- 简单实现高度平滑变化的ViewPager
- ArrayList和LinkedList的区别
- Floyd算法
- 牛客面经 | BAT、美团、360、滴滴新锐……2W字干货,这不仅仅是一篇面经
- Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance(info)
- LeetCode
- 神经网络中权值初始化的方法