concat对于字符串进行拼接
1 | concat(str1, str2, ..., strN) - Returns the concatenation of str1, str2, ..., strN. |
concat_ws在拼接的字符串中间添加某种格式
1 | concat_ws(sep, [str | array(str)]+) - Returns the concatenation of the strings separated by `sep`. |
decode转码
1 | decode(bin, charset) - Decodes the first argument using the second argument character set. |
encode设置编码格式
1 | encode(str, charset) - Encodes the first argument using the second argument character set. |
format_string/printf 格式化字符串
1 | format_string(strfmt, obj, ...) - Returns a formatted string from printf-style format strings. |
initcap将每个单词的首字母变为大写,其他字母小写; lower全部转为小写,upper大写
1 | initcap(str) - Returns `str` with the first letter of each word in uppercase. All other letters are in lowercase. Words are delimited by white space. |
length返回字符串的长度
1 | Examples:`> SELECT length('Spark SQL '); |
levenshtein编辑距离(将一个字符串变为另一个字符串的距离)
1 | levenshtein(str1, str2) - Returns the Levenshtein distance between the two given strings. |
lpad返回固定长度的字符串,如果长度不够,用某种字符补全,rpad右补全
1 | lpad(str, len, pad) - Returns `str`, left-padded with `pad` to a length of `len`. If `str` is longer than `len`, the return value is shortened to `len` characters. |
ltrim去除空格或去除开头的某些字符,rtrim右去除,trim两边同时去除
1 | ltrim(str) - Removes the leading space characters from `str`. |
regexp_extract 正则提取某些字符串,regexp_replace正则替换
1 | Examples:`> SELECT regexp_extract('100-200', '(\d+)-(\d+)', 1); |
repeat复制给的字符串n次
1 | Examples: `> SELECT repeat('123', 2); |
instr返回截取字符串的位置/locate
1 | instr(str, substr) - Returns the (1-based) index of the first occurrence of `substr` in `str`. |
space 在字符串前面加n个空格
1 | space(n) - Returns a string consisting of `n` spaces. |
split以某些字符拆分字符串
1 | split(str, regex) - Splits `str` around occurrences that match `regex`. |
substr截取字符串,substring_index
Examples:
1 | > SELECT substr('Spark SQL', 5); |
translate 替换某些字符串为
1 | Examples: `> SELECT translate('AaBbCc', 'abc', '123'); |
get_json_object
1 | get_json_object(json_txt, path) - Extracts a json object from `path`. |
unhex
1 | unhex(expr) - Converts hexadecimal `expr` to binary. |
to_json
to_json(expr[, options]) - Returns a json string with a given struct value
Examples:
1 | > SELECT to_json(named_struct('a', 1, 'b', 2)); |