Cypher projection returning "null" in results

The following cypher query is not returning anything in results, rather null.

  MATCH (scene:Scene)-[c:CONTAINS]->(object_obs:ObjectObservation)
  MATCH (object:Object)-[i:WAS_OBSERVED]->(lane:LaneObservation)
  WITH scene, object_obs, object, lane,
    {
      sceneNodeProperties: scene {scene_id: coalesce(scene.scene_id, 0)},
      obj_obsNodeProperties: object_obs {obj_obs: coalesce(object.obj_type, 0)},
      objectNodeProperties: object {obj_type: coalesce(object.obj_type, 0)},
      laneNodeProperties: lane {which_lane: coalesce(lane.which_lane, 0)}
    } AS properties
  WITH gds.graph.project(
    'sceneGraph',
    scene,
    object_obs,
    object,
    lane,
    properties
  ) AS g
  RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

I have verified that graph exists as expected based on the following data load:

 LOAD CSV WITH HEADERS FROM 'file:///ttraffic_scenario.csv' AS row
    MERGE (scene:Scene {scene_id: toFloat(row['scene_id']), timestamp: datetime(row['timestamp'])})
    MERGE (object:Object {obj_type: toFloat(row['obj_type']),obj_id: toFloat(row['obj_id'])})
    MERGE (object_obs:ObjectObservation {obj_type: toFloat(row['obj_type']),timestamp: (row['timestamp'])})
    MERGE (lane:LaneObservation {which_lane: toFloat(row['lane']),timestamp: (row['timestamp'])})
    MERGE (scene)-[:CONTAINS]->(object_obs)
    MERGE (object_obs)-[:IN_LANE]->(lane)
    MERGE (object)-[:WAS_OBSERVED]->(object_obs)

Input data example from CSV:

scene_id,obj_id,lane,obj_type,timestamp
1,1,1,1,2024-03-01T10:00:00
1,2,2,1,2024-03-01T10:00:00
1,3,3,2,2024-03-01T10:00:00
2,1,1,1,2024-03-01T10:00:01
2,2,2,1,2024-03-01T10:00:01
2,3,3,2,2024-03-01T10:00:01
3,1,1,1,2024-03-01T10:00:02
3,2,2,1,2024-03-01T10:00:02
3,3,3,2,2024-03-01T10:00:02

  • neo4j version: desktop version
  • what kind of API / driver do you use: Cypher

Based on your import, you don’t have a relation as described in your second match pattern. An Object node is not related to a LaneObservation node through a WAS_OBSERVED, relationship.

The Object is related to an ObjectObservation node

Btw- your two matches create a Cartesian product of each results because there not correlated. The second does not depend on the results of the first. Is this what you are looking to do?

1 Like

yes, i noticed that mix up now. thanks.
Nonetheless, I managed to get through via the following, still curious if we can do it without using "source" and "target" things which are provided in the documentation of Cypher projection on Neo4j.

  MATCH (source)-[r:CONTAINS|WAS_OBSERVED|IN_LANE]->(target)
  WHERE source:Scene OR source:Object OR source:ObjectObservation
  WITH gds.graph.project(
    '3sceneGraph',
    source,
    target,
    {
      sourceNodeProperties: source {scene_id: coalesce(source.scene_id, 0),obj_type: coalesce(source.obj_type, 0),obj_id: coalesce(source.obj_type, 0) },
      targetNodeProperties: target {obj_type: coalesce(target.obj_type, 0),which_lane: coalesce(target.which_lane, 0),obj_type: coalesce(target.obj_type, 0)}
    }
  ) as g
  RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

You could use a native projection instead of a cypher projection.

Native projection is not letting through any data other than floats; or is it possible to have timestamp info in native projection?
And now it seems like even Cypher projection is not supporting DateTime:

  MATCH (source)-[r:CONTAINS|WAS_OBSERVED|IN_LANE]->(target)
  WHERE source:Scene OR source:Object OR source:ObjectObservation
  WITH gds.graph.project(
    'imgraph1',
    source,
    target,
    {
      sourceNodeProperties: source {scene_id: coalesce(source.scene_id, 0),obj_type: coalesce(source.obj_type, 0), timestamp: coalesce(source.timestamp, 0),\
          obj_id: coalesce(source.obj_id, 0), which_lane: coalesce(source.which_lane, 0) , obj_obs: coalesce(source.obj_obs, 0)},
          
      targetNodeProperties: target {obj_type: coalesce(target.obj_type, 0),which_lane: coalesce(target.which_lane, 0),timestamp: coalesce(target.timestamp, 0),\
          scene_id: coalesce(target.scene_id, 0), obj_id: coalesce(target.obj_id, 0), obj_obs: coalesce(target.obj_obs, 0) }
    }
  ) as g
  RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rel

and it gives the following error

  neo4j.exceptions.ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message:
   Failed to invoke function `gds.graph.project`: Caused by: java.lang.IllegalArgumentException: Unsupported GDS node property of type `DateTime`.}