本系列文章主要介绍Spark SQL/Hive中常用的函数,主要分为字符串函数、JSON函数、时间函数、开窗函数以及在编写Spark SQL代码应用时实用的函数算子五个模块。
1. concat
对字符串进行拼接:concat(str1, str2, …, strN) ,参数:str1、str2…是要进行拼接的字符串。
-- return the concatenation of str1、str2、..., strN
-- SparkSQL
select concat('Spark', 'SQL');
2. concat_ws
在拼接的字符串中间添加某种分隔符:concat_ws(sep, [str | array(str)]+)。
参数1:分隔符,如 - ;参数2:要拼接的字符串(可多个)
-- return the concatenation of the strings separated by sep
-- Spark-SQL
select concat_ws("-", "Spark", "SQL");
3. encode
设置编码格式:encode(str, charset)。
参数1:要进行编码的字符串 ;参数2:使用的编码格式,如UTF-8
-- encode the first argument using the second argument character set
select encode("HIVE

本文介绍了Spark SQL和Hive中常用的字符串函数,包括concat、concat_ws、encode、decode、format_string/printf、initcap/lower/upper、length、lpad/rpad、trim/ltrim/rtrim、regexp_extract、regexp_replace、repeat、instr/locate、space、split、substr/substring_index和translate等。这些函数用于字符串操作,如拼接、编码、格式化、大小写转换、长度计算、正则表达式处理等。
最低0.47元/天 解锁文章
3200

被折叠的 条评论
为什么被折叠?



