String 在配置单元/Presto中将文件路径拆分为其组成路径

String 在配置单元/Presto中将文件路径拆分为其组成路径,string,split,hive,hiveql,presto,String,Split,Hive,Hiveql,Presto,使用Presto/Hive,我想按以下方式拆分字符串 输入字符串: \Users\Killer\Downloads\Temp \Users\Killer\Downloads\welcome 并让查询返回以下行: \Users\ \Users\Killer\ \Users\Killer\Downloads\ \Users\Killer\Downloads\Temp \Users\ \Users\Killer\ \Users\Killer\Downloads\ \Users\Killer\Down

使用Presto/Hive,我想按以下方式拆分字符串

输入字符串:

\Users\Killer\Downloads\Temp
\Users\Killer\Downloads\welcome
并让查询返回以下行:

\Users\
\Users\Killer\
\Users\Killer\Downloads\
\Users\Killer\Downloads\Temp
\Users\
\Users\Killer\
\Users\Killer\Downloads\
\Users\Killer\Downloads\welcome
谁能帮帮我吗。

这就可以了:

SELECT item, array_join( array_agg(item) over (order by id), '\' )
FROM UNNEST(split('\Users\Killer\Downloads\Temp','\')) WITH ORDINALITY t(item,id)
说明:


我们首先通过delimeter
\
将列表拆分为一个数组,然后将该数组拆分为行,每个项目一行。之后,我们对所有项目执行
array\u agg
,直到该行id(“滚动”窗口函数的聚合),最后我们使用
\
delimeter将它们连接回来。

蜂巢解决方案。拆分以获取数组,使用posexplode分解数组,使用分析函数再次收集数组并连接(文字
\
应使用一个反斜杠屏蔽-
\\
,在拆分中使用的正则表达式中,单个反斜杠表示为四个反斜杠):


您当然需要添加一些&。到目前为止,您尝试了什么?我正在运行以下查询,但结果将永远进入循环。我正在处理数百万条记录选择fsiamge.id,array\u join(array\u agg(item)over(order by id,level),从fsiamge交叉连接UNNEST(拆分(id,“/”)开始,顺序为t(项目,级别);
select s.level, 
        concat(concat_ws('\\',collect_set(s.path) over(order by level rows between unbounded preceding and current row)),
              case when level<size(split(t.str,'\\\\'))-1  then '\\' else '' end 
             ) result
  from mytable t lateral view posexplode(split(t.str,'\\\\')) s as level, path
level   result
0         \
1         \Users\
2         \Users\Killer\
3         \Users\Killer\Downloads\
4         \Users\Killer\Downloads\Temp