I’m trying to move from Neo4j to Memgraph. The following query uses a Neo4j specific feature that is not part of openCyper. I think they are called subqueries. Here’s a query that uses subqueries.
UNWIND $batch as row
MERGE (e:Entity {asset_id: row.asset_id, version: row.version, id: row.entity_id})
WITH e, row
CALL {
WITH row
WITH row WHERE row.has_parent=True AND row.parent <> ''
MATCH (a:Entity {asset_id: row.asset_id, version: row.version, id: row.entity_id})
SET a.fract_index = row.fract_index
}
WITH e, row
CALL {
WITH row
WITH row WHERE row.has_parent=True AND row.parent = ''
MATCH (a:Entity {asset_id: row.asset_id, version: row.version, id: row.entity_id})
REMOVE a.fract_index
}
WITH e, row
WITH node as e, row
MERGE (e)<-[:ATTACHED_TO]-(c:Component {asset_id: row.asset_id, version: row.version, id: row.component_id})
ON MATCH
SET
c.value = row.value
ON CREATE
SET
c.value = row.value
WITH e as child, row
CALL {
WITH child, row
// conditional execution
WITH child, row WHERE row.has_parent=True AND row.parent <> ''
MERGE (e:Entity {asset_id: row.asset_id, version: row.version, id: row.parent})
MERGE (e)<-[:CHILD_OF]-(child)
}
WITH child, row
CALL {
WITH child, row
WITH child, row WHERE row.has_parent = True AND row.parent = ''
MATCH (child:Entity {asset_id: row.asset_id, version: row.version, id: row.entity_id})-[r:CHILD_OF]->(:Entity)
DELETE r
}
WITH child, row
CALL {
WITH child, row
// conditional execution
WITH child, row WHERE row.referenced <> ''
MERGE (e:Entity {asset_id: row.asset_id, version: row.version, id: row.referenced})
MERGE (e)<-[:REFERS_TO]-(child)
}
Is it possible to express this query in OpenCypher so that it works against Memgraph?