reduce函数

    在openCypher中,reduce()函数没有定义。nGQL使用了Cypher方式实现reduce()函数。

    1. nebula> RETURN reduce(totalNum = 10, n IN range(1, 3) | totalNum + n) AS r;
    2. +----+
    3. | r |
    4. +----+
    5. | 16 |
    6. +----+
    7. nebula> RETURN reduce(totalNum = -4 * 5, n IN [1, 2] | totalNum + n * 2) AS r;
    8. +-----+
    9. | r |
    10. | -14 |
    11. nebula> MATCH p = (n:player{name:"LeBron James"})<-[:follow]-(m) \
    12. RETURN nodes(p)[0].age AS src1, nodes(p)[1].age AS dst2, \
    13. reduce(totalAge = 100, n IN nodes(p) | totalAge + n.age) AS sum;
    14. +------+------+-----+
    15. | src1 | dst2 | sum |
    16. +------+------+-----+
    17. | 34 | 31 | 165 |
    18. +------+------+-----+
    19. | 34 | 29 | 163 |
    20. +------+------+-----+
    21. | 34 | 33 | 167 |
    22. +------+------+-----+
    23. | 34 | 26 | 160 |
    24. +------+------+-----+
    25. | 34 | 37 | 171 |
    26. +------+------+-----+
    27. nebula> LOOKUP ON player WHERE player.name == "Tony Parker" \
    28. | GO FROM $-.VertexID over follow \
    29. WHERE follow.degree != reduce(totalNum = 5, n IN range(1, 3) | $$.player.age + totalNum + n) \
    30. YIELD $$.player.name AS id, $$.player.age AS age, follow.degree AS degree;
    31. +---------------------+-----+--------+
    32. | id | age | degree |
    33. +---------------------+-----+--------+
    34. | "Tim Duncan" | 42 | 95 |
    35. +---------------------+-----+--------+
    36. | "LaMarcus Aldridge" | 33 | 90 |
    37. +---------------------+-----+--------+
    38. +---------------------+-----+--------+