RedisGraph中exists()函数结果不符合预期的问题求助
RedisGraph中Cypher EXISTS()函数行为不符合预期
问题说明
我有一段在Neo4j中运行正常的Cypher查询,在RedisGraph中却无法得到预期结果。查询语句如下:
MATCH (dp:DataProduct {name: 'DataProduct1'})-[:CONTAINS]->(t:Table {name: 'output_table'})-[:HAS_COLUMN]->(c:Column {name: 'foo'}) RETURN exists((c)-[:TRANSFORMATION]->())
当列c没有向外的TRANSFORMATION关系时,预期该查询返回false,但在RedisGraph中,只要查询的前半部分匹配到节点,结果始终为true。
复现步骤
可通过以下Cypher语句生成测试数据:
MERGE (dp:DataProduct {name: 'DataProduct1'}) RETURN dp MATCH (dp:DataProduct {name: 'DataProduct1'}) MERGE (dp)-[:CONTAINS]->(t:Table {name: 'output_table'}) MATCH (dp:DataProduct {name: 'DataProduct1'})-[:CONTAINS]->(t:Table {name: 'output_table'}) MERGE (t)-[:HAS_COLUMN]->(c:Column {name: 'foo'}) MERGE (dp:DataProduct {name: 'DataProduct2'}) RETURN dp MATCH (dp:DataProduct {name: 'DataProduct2'}) MERGE (dp)-[:CONTAINS]->(t:Table {name: 'input_table'}) MATCH (dp:DataProduct {name: 'DataProduct2'})-[:CONTAINS]->(t:Table {name: 'input_table'}) MERGE (t)-[:HAS_COLUMN]->(c:Column {name: 'bar'}) MATCH (sourceDp:DataProduct {name: 'DataProduct2'})-[:CONTAINS]->(sourceT:Table {name: 'input_table'})-[:HAS_COLUMN]->(sourceC:Column {name: 'bar'}) MATCH (targetDp:DataProduct {name: 'DataProduct1'})-[:CONTAINS]->(targetT:Table {name: 'output_table'})-[:HAS_COLUMN]->(targetC:Column {name: 'foo'}) MERGE (sourceC)-[r:TRANSFORMATION]->(targetC) SET r.type = 'function', r.code = 'CONCAT(foo and bar)'
生成的图谱结构:
- DataProduct1包含output_table表,该表有foo列
- DataProduct2包含input_table表,该表有bar列,且bar列通过TRANSFORMATION关系指向DataProduct1的foo列
额外创建无关联节点的语句:
MERGE (dp:DataProduct {name: 'DataProduct3'}) RETURN dp MATCH (dp:DataProduct {name: 'DataProduct3'}) MERGE (dp)-[:CONTAINS]->(t:Table {name: 'whatever'}) MATCH (dp:DataProduct {name: 'DataProduct3'})-[:CONTAINS]->(t:Table {name: 'whatever'}) MERGE (t)-[:HAS_COLUMN]->(c:Column {name: 'foobar'})
DataProduct3的foobar列既无传入也无传出的TRANSFORMATION关系。
基于上述数据,预期以下查询返回true:
MATCH (dp:DataProduct {name: 'DataProduct2'})-[:CONTAINS]->(t:Table {name: 'input_table'})-[:HAS_COLUMN]->(c:Column {name: 'bar'}) RETURN exists((c)-[:TRANSFORMATION]->())
预期以下查询返回false:
MATCH (dp:DataProduct {name: 'DataProduct1'})-[:CONTAINS]->(t:Table {name: 'output_table'})-[:HAS_COLUMN]->(c:Column {name: 'foo'}) RETURN exists((c)-[:TRANSFORMATION]->())
但在RedisGraph中,两个查询均返回true;甚至查询foobar列的语句也返回true:
MATCH (dp:DataProduct {name: 'DataProduct3'})-[:CONTAINS]->(t:Table {name: 'whatever'})-[:HAS_COLUMN]->(c:Column {name: 'foobar'}) RETURN exists((c)-[:TRANSFORMATION]->())
临时解决方法
我已改用count()重写查询,该方法可得到正确结果,特此补充供其他开发者参考:
MATCH (dp:DataProduct {name: 'DataProduct1'})-[:CONTAINS]->(t:Table {name: 'output_table'})-[:HAS_COLUMN]->(c:Column {name: 'foo'})-[:TRANSFORMATION]->() RETURN COUNT(dp) > 0
请问我哪里操作有误?
内容的提问来源于stack exchange,提问作者Jonck van der Kogel
相关产品推荐
相关产品推荐

