'jj' and 'gg' are not defined. Are these supposed to be 'bmxh' and 'cmrh'? If so, I think this simplified query should result in the same result. Maybe it avoids the error.
CALL {
MATCH (qlwe:Fan)-[mmkt:BORN_ON_MONTH]->(xbqe:Month)
WHERE xbqe.name = '01'
RETURN COLLECT(apoc.map.merge({id: ID(qlwe)}, qlwe)) AS xodv
}
CALL {
MATCH (zdfy:Fan)-[bdkl:BORN_ON_DAY]->(krcq:Day)
WHERE krcq.name = '20'
RETURN COLLECT(apoc.map.merge({id: ID(zdfy)}, zdfy)) AS zqqz
}
UNWIND apoc.coll.intersection(xodv,zqqz) AS result
RETURN result
UNION
CALL {
MATCH (zazq:Player)-[eize:BORN_ON_MONTH]->(xmwc:Month)
WHERE xmwc.name = '01'
RETURN COLLECT(apoc.map.merge({id: ID(zazq)}, zazq)) AS oemm
}
CALL {
MATCH (ceah:Player)-[yqgt:BORN_ON_DAY]->(ychy:Day)
WHERE ychy.name = '20'
RETURN COLLECT(apoc.map.merge({id: ID(ceah)}, ceah)) AS eqci
}
UNWIND apoc.coll.intersection(eqci,oemm) AS result
RETURN result
Just a note on the apoc.merge.map usages. The function takes two maps as its parameters, but in all four uses the second parameter being passed is a node. I think the second parameter should be properties(node) instead, as properties will return a map of the node’s properties.
You can also get the same result directly with map projection, eliminating the need for apoc.map.merge. Collect the following instead, where ‘x’ represents the node variable. This will create a map with all the node’s properties and its id.
Just thinking, this should give you the same results and may be more efficient. It calculates the intersection of a list of nodes instead of a list of maps.
CALL {
MATCH (qlwe:Fan)-[mmkt:BORN_ON_MONTH]->(xbqe:Month)
WHERE xbqe.name = '01'
RETURN COLLECT(qlwe) AS xodv
}
CALL {
MATCH (zdfy:Fan)-[bdkl:BORN_ON_DAY]->(krcq:Day)
WHERE krcq.name = '20'
RETURN COLLECT(zdfy) AS zqqz
}
UNWIND apoc.coll.intersection(xodv, zqqz) AS x
RETURN x{.*, id: id(x)} as result
UNION
CALL {
MATCH (zazq:Player)-[eize:BORN_ON_MONTH]->(xmwc:Month)
WHERE xmwc.name = '01'
RETURN COLLECT(zazq) AS oemm
}
CALL {
MATCH (ceah:Player)-[yqgt:BORN_ON_DAY]->(ychy:Day)
WHERE ychy.name = '20'
RETURN COLLECT(ceah) AS eqci
}
UNWIND apoc.coll.intersection(eqci, oemm) AS x
RETURN x{.*, id: id(x)} as result
Sorry, last refactor. It looks like the logic is finding the set of 'Fan' nodes that have both a specific relationship to a 'Month' node and a 'Day' node. This is implemented by finding both set of 'Fan' nodes and calculating the intersection, which represents the set of nodes in both sets. This logic can be replaced by finding the set of 'Fan' nodes that have a path to both the specific 'Month' node and the specific 'Day' node. That is what the logic does in the below query.
The same is true for the 'Player' nodes.
MATCH (fan:Fan)
WHERE EXISTS {
MATCH (fan)-[:BORN_ON_MONTH]->(xbqe:Month)
WHERE xbqe.name = '01'
}
AND EXISTS {
MATCH (fan)-[:BORN_ON_DAY]->(krcq:Day)
WHERE krcq.name = '20'
}
RETURN fan{.*, id: id(fan)} as result
UNION
MATCH (player:Player)
WHERE EXISTS {
MATCH (player)-[:BORN_ON_MONTH]->(xmwc:Month)
WHERE xmwc.name = '01'
}
AND EXISTS {
MATCH (player)-[:BORN_ON_DAY]->(ychy:Day)
WHERE ychy.name = '20'
}
RETURN player{.*, id: id(player)} as result