0


大数据之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(select1as id_start,100as 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不仅炸出一个值还附带索引号;

标签: big data hive 大数据

本文转载自: https://blog.csdn.net/weixin_43597208/article/details/123151294
版权归原作者 浊酒南街 所有, 如有侵权,请联系我们删除。

“大数据之Hive:space函数”的评论:

还没有评论