列表函数

Nebula Graph支持以下列表(List)函数。

函数说明
keys(expr)返回一个列表,包含字符串形式的点、边或映射的所有属性。
labels(vertex)返回点的Tag列表。
nodes(path)返回路径中所有点的列表。
range(start, end [, step])返回[start,end]范围内固定步长的列表,默认步长step为1。
relationships(path)返回路径中所有关系的列表。
reverse(list)返回将原列表逆序排列的新列表。
tail(list)返回不包含原列表第一个元素的新列表.
head(list)返回列表的第一个元素。
last(list)返回列表的最后一个元素。
coalesce(list)返回列表中第一个非空元素。
reduce()请参见reduce函数

Note

如果参数为NULL,则输出结果是未定义的。

示例

  1. nebula> WITH [NULL, 4923, 'abc', 521, 487] AS ids \
  2. RETURN reverse(ids), tail(ids), head(ids), last(ids), coalesce(ids);
  3. +-----------------------------------+-------------------------+-----------+-----------+---------------+
  4. | reverse(ids) | tail(ids) | head(ids) | last(ids) | coalesce(ids) |
  5. +-----------------------------------+-------------------------+-----------+-----------+---------------+
  6. | [487, 521, "abc", 4923, __NULL__] | [4923, "abc", 521, 487] | __NULL__ | 487 | 4923 |
  7. +-----------------------------------+-------------------------+-----------+-----------+---------------+
  8. nebula> MATCH (a:player)-[r]->() \
  9. WHERE id(a) == "player100" \
  10. RETURN labels(a), keys(r);
  11. +------------+----------------------------+
  12. | labels(a) | keys(r) |
  13. +------------+----------------------------+
  14. | ["player"] | ["degree"] |
  15. | ["player"] | ["degree"] |
  16. | ["player"] | ["end_year", "start_year"] |
  17. +------------+----------------------------+
  18. nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) \
  19. WHERE a.name == "Tim Duncan" AND c.name == "Spurs" \
  20. RETURN nodes(p);
  21. +-----------------------------------------------------------------------------------------------------------------------------------------------+
  22. | nodes(p) |
  23. +-----------------------------------------------------------------------------------------------------------------------------------------------+
  24. | [("player100" :player{age: 42, name: "Tim Duncan"}), ("player101" :player{age: 36, name: "Tony Parker"}), ("team204" :team{name: "Spurs"})] |
  25. | [("player100" :player{age: 42, name: "Tim Duncan"}), ("player125" :player{age: 41, name: "Manu Ginobili"}), ("team204" :team{name: "Spurs"})] |
  26. +-----------------------------------------------------------------------------------------------------------------------------------------------+
  27. nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) WHERE a.name == "Tim Duncan" AND c.name == "Spurs" RETURN relationships(p);
  28. +-----------------------------------------------------------------------------------------------------------------------------+
  29. | relationships(p) |
  30. +-----------------------------------------------------------------------------------------------------------------------------+
  31. | [[:follow "player100"->"player101" @0 {degree: 95}], [:serve "player101"->"team204" @0 {end_year: 2018, start_year: 1999}]] |
  32. | [[:follow "player100"->"player125" @0 {degree: 95}], [:serve "player125"->"team204" @0 {end_year: 2018, start_year: 2002}]] |
  33. +-----------------------------------------------------------------------------------------------------------------------------+

最后更新: October 27, 2021