大数据之Hive:space函数
Posted 浊酒南街
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大数据之Hive:space函数相关的知识,希望对你有一定的参考价值。
目录
1、空格字符串函数:space
语法: space(int n)
返回值: string
说明:返回长度为n的空格字符串
举例:
hive> select space(10) from dual;
hive> select length(space(10)) from dual;
10
2、space函数与split函数结合,得到数组;
space函数与split函数结合,可以得到空格字符串数组
举例:
hive>select split(space(10), '');
[" "," "," "," "," "," "," "," "," "," ",""]
3、如何产生1-100的连续的数字?
结合space函数与split函数,posexplode函数,lateral view函数获得
实现方法一:
select
id_start+pos as id
from(
select
1 as id_start,
100 as id_end
) m lateral view posexplode(split(space(id_end-id_start), '')) t as pos, val
实现方法二:
select
row_number() over() as id
from
(select split(space(99), ' ') as x) t
lateral view
explode(x) ex;
备注:explode(x)和posexplode()均为炸裂函数,区别在于explode炸出一个值,posexplode不仅炸出一个值还附带索引号;
以上是关于大数据之Hive:space函数的主要内容,如果未能解决你的问题,请参考以下文章