HIVE:如果存在则替换行中的字符串/模式,否则什么都不做
HIVE : Replace string/ pattern in row if it exists else do nothing
我有一个 table A,有 id、名字、年龄。
> id name age
> {20} Joan 12
> 3 James 12
> 12 Jill 12
> {54} Adam 12
> {10} Bill 12
我需要删除 'id' 字段周围的 {}。
我试过了:
translate(regexp_extract(id, '([^{])([^}])', 2), '{', '')
这有效,但对于没有 {} 的值返回空值。
id
3
12
有什么方法可以得到输出结果???
id
20
3
12
54
10
您可以使用 regexp_replace udf 来删除“{}”,例如:
select regexp_replace(id, '\{|\}','');
请尝试以下 select 语句:
select regexp_replace(col1,'[{}]','') as replaced,col2,col3 from table_name;
我有一个 table A,有 id、名字、年龄。
> id name age
> {20} Joan 12
> 3 James 12
> 12 Jill 12
> {54} Adam 12
> {10} Bill 12
我需要删除 'id' 字段周围的 {}。 我试过了:
translate(regexp_extract(id, '([^{])([^}])', 2), '{', '')
这有效,但对于没有 {} 的值返回空值。
id
3
12
有什么方法可以得到输出结果???
id
20
3
12
54
10
您可以使用 regexp_replace udf 来删除“{}”,例如:
select regexp_replace(id, '\{|\}','');
请尝试以下 select 语句:
select regexp_replace(col1,'[{}]','') as replaced,col2,col3 from table_name;