Neo4J cypher: remove loops from flattened resultset

回眸只為那壹抹淺笑 提交于 2020-01-16 08:35:33

问题


This is an extension of the following question:

I have a data lineage related graph in Neo4J with variable length path containing intermediate nodes (tables) as an array:

match p=(s)-[r:airflow_loads_to*]->(t)
where s.database_name='hive'
and s.schema_name='test'
and s.name="source_table"
return s.name, [n in nodes(p) | n.name] as arrayOfName,t.name

Now, this resultset contains loops that I want to omit. I can 'remove' these loops without the flattening ArrayOfName result by running:

match p=(s)-[r:airflow_loads_to*]->(t)
where s.database_name='hive'
and s.schema_name='test'
and s.name="source_table"
return s.name, min(size(r)) as pathlen, t.name
order by pathlen

However, when I add ArrayOfName back, the resultset contains all rows again. I guess this means chaining the results somehow, using the pathlen as a filter or preventing that loops exist in the path p at all. But I am stuck on how to accomplish this...


回答1:


did you try

p=shortestPath((s)-[r:airflow_loads_to*]->(t))

because it seems that is what you need



来源:https://stackoverflow.com/questions/59735441/neo4j-cypher-remove-loops-from-flattened-resultset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!