谓词函数

谓词函数只返回truefalse,通常用于WHERE子句中。

Nebula Graph支持以下谓词函数。

函数说明
exists()如果指定的属性在点、边或映射中存在,则返回true,否则返回false
any()如果指定的谓词适用于列表中的至少一个元素,则返回true,否则返回false
all()如果指定的谓词适用于列表中的每个元素,则返回true,否则返回false
none()如果指定的谓词不适用于列表中的任何一个元素,则返回true,否则返回false
single()如果指定的谓词适用于列表中的唯一一个元素,则返回true,否则返回false

Note

如果列表为空,或者列表中的所有元素都为空,则返回NULL。

Compatibility

在 openCypher 中只定义了函数exists(),其他几个函数依赖于具体实现。

语法

  1. <predicate>(<variable> IN <list> WHERE <condition>)

示例

  1. nebula> RETURN any(n IN [1, 2, 3, 4, 5, NULL] \
  2. WHERE n > 2) AS r;
  3. +------+
  4. | r |
  5. +------+
  6. | true |
  7. +------+
  8. nebula> RETURN single(n IN range(1, 5) \
  9. WHERE n == 3) AS r;
  10. +------+
  11. | r |
  12. +------+
  13. | true |
  14. +------+
  15. nebula> RETURN none(n IN range(1, 3) \
  16. WHERE n == 0) AS r;
  17. +------+
  18. | r |
  19. +------+
  20. | true |
  21. +------+
  22. nebula> WITH [1, 2, 3, 4, 5, NULL] AS a \
  23. RETURN any(n IN a WHERE n > 2);
  24. +-------------------------+
  25. | any(n IN a WHERE (n>2)) |
  26. +-------------------------+
  27. | true |
  28. +-------------------------+
  29. nebula> MATCH p = (n:player{name:"LeBron James"})<-[:follow]-(m) \
  30. RETURN nodes(p)[0].name AS n1, nodes(p)[1].name AS n2, \
  31. all(n IN nodes(p) WHERE n.name NOT STARTS WITH "D") AS b;
  32. +----------------+-------------------+-------+
  33. | n1 | n2 | b |
  34. +----------------+-------------------+-------+
  35. | "LeBron James" | "Danny Green" | false |
  36. +----------------+-------------------+-------+
  37. | "LeBron James" | "Dejounte Murray" | false |
  38. +----------------+-------------------+-------+
  39. | "LeBron James" | "Chris Paul" | true |
  40. +----------------+-------------------+-------+
  41. | "LeBron James" | "Kyrie Irving" | true |
  42. +----------------+-------------------+-------+
  43. | "LeBron James" | "Carmelo Anthony" | true |
  44. +----------------+-------------------+-------+
  45. | "LeBron James" | "Dwyane Wade" | false |
  46. +----------------+-------------------+-------+
  47. nebula> MATCH p = (n:player{name:"LeBron James"})-[:follow]->(m) \
  48. RETURN single(n IN nodes(p) WHERE n.age > 40) AS b;
  49. +------+
  50. | b |
  51. +------+
  52. | true |
  53. +------+
  54. nebula> MATCH (n:player) \
  55. RETURN exists(n.id), n IS NOT NULL;
  56. +--------------+---------------+
  57. | exists(n.id) | n IS NOT NULL |
  58. +--------------+---------------+
  59. | false | true |
  60. +--------------+---------------+
  61. ...
  62. nebula> MATCH (n:player) \
  63. WHERE exists(n['name']) RETURN n;
  64. +-------------------------------------------------------------------------------------------------------------+
  65. | n |
  66. +-------------------------------------------------------------------------------------------------------------+
  67. | ("Grant Hill" :player{age: 46, name: "Grant Hill"}) |
  68. +-------------------------------------------------------------------------------------------------------------+
  69. | ("Marc Gasol" :player{age: 34, name: "Marc Gasol"}) |
  70. +-------------------------------------------------------------------------------------------------------------+
  71. ...

最后更新: July 6, 2021