列表函数

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

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

示例

  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. +------------+----------------------------+
  16. | ["player"] | ["degree"] |
  17. +------------+----------------------------+
  18. | ["player"] | ["end_year", "start_year"] |
  19. +------------+----------------------------+
  20. nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) \
  21. WHERE a.name == "Tim Duncan" AND c.name == "Spurs" \
  22. RETURN nodes(p);
  23. +-----------------------------------------------------------------------------------------------------------------------------------------------+
  24. | nodes(p) |
  25. +-----------------------------------------------------------------------------------------------------------------------------------------------+
  26. | [("player100" :player{age: 42, name: "Tim Duncan"}), ("player101" :player{age: 36, name: "Tony Parker"}), ("team204" :team{name: "Spurs"})] |
  27. +-----------------------------------------------------------------------------------------------------------------------------------------------+
  28. | [("player100" :player{age: 42, name: "Tim Duncan"}), ("player125" :player{age: 41, name: "Manu Ginobili"}), ("team204" :team{name: "Spurs"})] |
  29. +-----------------------------------------------------------------------------------------------------------------------------------------------+
  30. nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) WHERE a.name == "Tim Duncan" AND c.name == "Spurs" RETURN relationships(p)
  31. +-----------------------------------------------------------------------------------------------------------------------------+
  32. | relationships(p) |
  33. +-----------------------------------------------------------------------------------------------------------------------------+
  34. | [[:follow "player100"->"player101" @0 {degree: 95}], [:serve "player101"->"team204" @0 {end_year: 2018, start_year: 1999}]] |
  35. +-----------------------------------------------------------------------------------------------------------------------------+
  36. | [[:follow "player100"->"player125" @0 {degree: 95}], [:serve "player125"->"team204" @0 {end_year: 2018, start_year: 2002}]] |
  37. +-----------------------------------------------------------------------------------------------------------------------------+