Hive 在蜂巢中寻找子串

Hive 在蜂巢中寻找子串,hive,impala,Hive,Impala,我正在尝试从字符串(组合键)获取子字符串值: 我的复合_键如下所述: string1|string2|string3|string4|string5|string6|string7 我能够使用impala的子字符串方法找到string1、string2、string3、string4和string5 有人能帮我用子串方法找到String6和String7吗 任何帮助都将被拒绝。我可以通过以下查询完成: 对于String7 select substring(composite_key,loca

我正在尝试从字符串(组合键)获取子字符串值: 我的复合_键如下所述:

string1|string2|string3|string4|string5|string6|string7 
我能够使用impala的子字符串方法找到string1、string2、string3、string4和string5

有人能帮我用子串方法找到String6和String7吗


任何帮助都将被拒绝。

我可以通过以下查询完成:

对于String7

select substring(composite_key,locate('|',composite_key,locate('|',composite_key,locate('|',composite_key,locate('|',composite_key,locate('|',composite_key, locate('|',composite_key) + 1)+1)+1)+1)+1)+1)as a
对于String6

select
substring(composite_key,
locate('|',composite_key,
locate('|',composite_key,
locate('|',composite_key,
locate('|',composite_key, 
locate('|',composite_key) + 1)+1)+1)+1)+1, 
locate('|',composite_key,
locate('|',composite_key,
locate('|',composite_key,
locate('|',composite_key,
locate('|',composite_key, 
locate('|',composite_key) + 1)+1)+1)+1)+1)
- locate('|',composite_key,
locate('|',composite_key,
locate('|',composite_key,
locate('|',composite_key, 
locate('|',composite_key) + 1)+1)+1)+1)-1) 
as a

您必须使用配置单元子查询+数组数据结构+拆分函数来完成此任务。然而,这只在蜂箱中有效。Impala还不支持嵌套数据结构,除了Impala 2.3(对应CDH 5.5)及更高版本中基于拼花地板的表

select 
key_array[0] part0,
key_array[1] part1, 
key_array[2] part2, 
key_array[3] part3, 
key_array[4] part4, 
key_array[5] part5, 
key_array[6] part6, 
from (
select split(composite_key,'|') as key_array 
from mytable
) as temp

请张贴一些你正在做的示例代码