Hive 查询拆分列数据并存储到多条记录中

Hive query to split column data and store into multiple records

有人可以建议我如何使用以下详细信息编写 Hive SQL 查询。

谁能帮我如何拆分列数据并将其作为新记录放置而不使用任何默认函数。 提前致谢。

使用posexplode,split.Since您需要拆分列的索引匹配,您将需要使用posexplode创建索引并确保它们在将列转换为行时匹配。

select Name, Phone, Address 
from table 
      lateral view posexplode(split(Phone,':')) Phone AS index1, Phone
      lateral view posexplode(split(Address,',')) Address AS index2, Address
where index1=index2;

如果我们不知道用于此的 pre-defined 函数。我们可以编写如下自定义逻辑(仅当我们知道分隔符和#of splits)。

select name, substr(phone,instr(phone,':',1)-1) phone, substr(address,instr(address,',',1)-1)
union all 
select name, substr(phone,instr(phone,':',2)-1) phone, substr(address,instr(address,',',2)-1)
union all 
select name, substr(phone,instr(phone,':',2)+1,length(phone)) phone, substr(address,instr(address,',',2)+1,length(address))

如果我们不知道预定义的方法,这可能会有所帮助。