从字符串中提取值并将其作为计算放入另一列中
我在 Impala
的一列中有一些字符串,就像
'class:104;teacher:ted;school:first;subclass:404'
'class:105;teacher:nick;subclass:650;students:400'
我想做一个
case when info like '%class%' then substr(info,6,3) end as class
case when info like '%subclass%' then **<Here to take the value of the subclass>** end as subclass
我该怎么做?正如你所看到的,它不是位置性的,以便与 substr() 一起使用
I have some strings in a column in Impala
like
'class:104;teacher:ted;school:first;subclass:404'
'class:105;teacher:nick;subclass:650;students:400'
I want to do a
case when info like '%class%' then substr(info,6,3) end as class
case when info like '%subclass%' then **<Here to take the value of the subclass>** end as subclass
How can I do it? As you can see it is not positional in order to go with substr()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以在这里使用 split_part() 。
类 -
split_part(split_part(col, 'class:',2),';',1)
subclass -
split_part(split_part(col, 'subclass:',2),';',1)
内部拆分将在类单词上拆分并获取第二部分('104;teacher:ted;school:第一;子类:404')。然后最外层的分割部分将在 上分割;并拿起第一部分(104)。
你的 SQL 应该是这样的 -
I think you can use split_part() here.
class -
split_part(split_part(col, 'class:',2),';',1)
subclass -
split_part(split_part(col, 'subclass:',2),';',1)
Inner split will split on class word and take second part('104;teacher:ted;school:first;subclass:404'). Then outermost split part will split on ; and pick up first part (104).
Your SQL should be like -