presto中常见字符串函数操作

1、字符串截取substr

presto语法:

substr(string, start, length) → varchar   如: select substr('1599319787151',1,10) 

substr(string, start) → varchar        如: select substr('1599319787151',1)

而hive中:substr和substring都可以使用

2、字符串替换regexp_replace

presto语法:

regexp_replace(stringpatternreplacement) → varchar

 如:select  regexp_replace('{\\"over\\":\\"0\\",\\"seckill\\":\\"0\\"}','\\','')

3、字符串首次出现位置position(下标从1开始的)

presto语法:

position(substring IN string) → bigint  如:select position('aa' in '15993aa1978715aa1') 

而hive中:select INSTR('15993aa1978715aa1','aa')  

4、字符串连接concat

presto语法:concat(string1, ..., stringN) → varchar  如:select  concat('kk','rrr')

而hive中除了concat,还有concat_ws按分隔符分割,如:select concat_ws("-","iii","rrr","kkk")

5、字符串分割split

presto语法:

split(string, delimiter) -> array(varchar)  如:SELECT split('a,b,c,d',',')  得到:[a, b, c, d]

split_part(string, delimiter, index) → varchar 如:SELECT split_part('a,b,c,d',',',2)  得到:b
 

String Functions and Operators — Presto 0.277 Documentationhttps://prestodb.io/docs/current/functions/string.html

Regular Expression Functions — Presto 0.277 Documentationhttps://prestodb.io/docs/current/functions/regexp.html?highlight=regexp_replace#id3 

你可能感兴趣的:(Presto,hive,hadoop,数据仓库)