Sql 在Hadoop中,如何截断空格后的文本?

Sql 在Hadoop中,如何截断空格后的文本?,sql,string,hadoop,hive,hiveql,Sql,String,Hadoop,Hive,Hiveql,我有一个列,即column_1,其值为: abc 12edf hbnm 847 47sf hg41 我需要如下输出: abc hbnm 47sf PS:我对db有只读访问权使用regexp_extract(col,“^(.*?\\s',1)从regexp中空格(组1)之前的字符串开头提取所有内容 “^(.*?\\s”表示: ^-字符串锚的开头 (.*)-任意字符任意次数 \\s-空格 Demo: with your_table as (--use your_table instead of

我有一个列,即
column_1
,其值为:

abc 12edf
hbnm 847
47sf hg41
我需要如下输出:

abc
hbnm
47sf
PS:我对db有只读访问权

使用
regexp_extract(col,“^(.*?\\s',1)
从regexp中空格(组1)之前的字符串开头提取所有内容

“^(.*?\\s”
表示:

^
-字符串锚的开头
(.*)
-任意字符任意次数
\\s
-空格

Demo:
with your_table as (--use your_table instead of this
select stack (3,
'abc  12edf',
'hbnm 847',
'47sf hg41'
) as str
)

select regexp_extract (str,'^(.*?)\\s',1) as result_str 
  from your_table s
结果:

abc
hbnm
47sf
另一种可能的解决方案是使用
split

select split (str,' ')[0] as result_str
还有一个使用
instr
+
substr
的解决方案:

select substr(str,1,instr(str,' ')-1)