Hive 如何在配置单元表中拆分字符串
我有一个表Hive 如何在配置单元表中拆分字符串,hive,Hive,我有一个表emp,它看起来像这样: +----------+----+ |customerID|name| +----------+----+ | 1| Ram| | 2| Raj| +----------+----+ 我希望分割每条记录的字符串,并希望在配置单元中输出如下所示: +----------+----+---+ |customerID|name|req| +----------+----+---+ | 1| Ram| R| |
emp
,它看起来像这样:
+----------+----+
|customerID|name|
+----------+----+
| 1| Ram|
| 2| Raj|
+----------+----+
我希望分割每条记录的字符串,并希望在配置单元中输出如下所示:
+----------+----+---+
|customerID|name|req|
+----------+----+---+
| 1| Ram| R|
| 1| Ram| a|
| 1| Ram| m|
| 1| Ram| |
| 2| Raj| R|
| 2| Raj| a|
| 2| Raj| j|
| 2| Raj| |
+----------+----+---+
您必须在配置单元中将名称列转换为数组类型,然后分解以获得所需的结果。 例如:
移除空白空间。
select customerID,req from (select *,explode(split(name,'')) as req from emp) where req != ''
+----------+---+
|customerID|req|
+----------+---+
| 1| R|
| 1| a|
| 1| m|
| 2| R|
| 2| a|
| 2| j|
+----------+---+
select customerID,req from (select *,explode(split(name,'')) as req from emp) where req != ''
+----------+---+
|customerID|req|
+----------+---+
| 1| R|
| 1| a|
| 1| m|
| 2| R|
| 2| a|
| 2| j|
+----------+---+