问题
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