neo4j / graph-data-science

Source code for the Neo4j Graph Data Science library of graph algorithms.
https://neo4j.com/docs/graph-data-science/current/
Other
637 stars 161 forks source link

gds.shortestPath.dijkstra.stream not return relationship type #329

Open johnfercher opened 1 month ago

johnfercher commented 1 month ago

Is your feature request related to a problem? Please describe.

I have a graph with multiple edge types and I need to retrieve the shortest path having the edge type of each one. I'm trying to execute the follow query:

MATCH (source:City {id: 'natal'}), (target:City {id: 'pelotas'})
CALL gds.shortestPath.dijkstra.stream('projection', {
    sourceNode: source,
    targetNodes: target,
    relationshipWeightProperty: 'distance_km'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs, path
RETURN
    index,
    gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    totalCost,
    [nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
    costs,
    nodes(path) as path
ORDER BY index

It works, but I don´t know how to retrieve the relationship types. Executing this query in localhost:7474 if return edge types, but the text don't.

Screenshot from 2024-09-15 23-38-59

I didn't find a way to retrieve this info using the documentation. This is my projection.

MATCH (a:City)-[r]->(b:City)
RETURN gds.graph.project(
  'projection',
  a,
  b,
  { 
    relationshipProperties: r { .distance_km },
    relationshipType: type(r)
  }
)

Describe the solution you would like

I would like a way to retrieve the relationship type as I retrieve the costs. Example, by adding a type after path.

MATCH (source:City {id: 'natal'}), (target:City {id: 'pelotas'})
CALL gds.shortestPath.dijkstra.stream('projection', {
    sourceNode: source,
    targetNodes: target,
    relationshipWeightProperty: 'distance_km'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs, path, relationshipType
RETURN
    index,
    gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    totalCost,
    [nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
    costs,
    nodes(path) as path,
    relationshipType
ORDER BY index

Describe alternatives you have considered

Additional context

vnickolov commented 1 month ago

@johnfercher thank you for creating this issue, we have put it in our backlog, however there is no concrete timeline on when it will be available in GDS.