比较符

Nebula Graph支持的比较符如下。

符号说明
=赋值
+加法
-减法
*乘法
/除法
==相等
!=, <>不等于
>大于
>=大于等于
<小于
<=小于等于
%取模
-负数符号
IS NULL为NULL
IS NOT NULL不为NULL
IS EMPTY不存在
IS NOT EMPTY存在

比较操作的结果是true或者false

Note

  • 比较不同类型的值通常没有定义,结果可能是NULL或其它。

  • EMPTY当前仅用于判断,不支持函数或者运算操作,包括且不限于GROUP BYcount()sum()max()hash()collect()+*

OpenCypher兼容性

  • NULL的比较操作和openCypher不同,行为也可能会改变。在openCypher中,IS [NOT] NULL通常与OPTIONAL MATCH一起使用,但是nGQL不支持OPTIONAL MATCH

  • openCypher中没有EMPTY,因此不支持在MATCH语句中使用EMPTY

示例

==

字符串比较时,会区分大小写。不同类型的值不相等。

Note

nGQL中的相等符号是==,openCypher中的相等符号是=

  1. nebula> RETURN 'A' == 'a', toUpper('A') == toUpper('a'), toLower('A') == toLower('a');
  2. +------------+------------------------------+------------------------------+
  3. | ("A"=="a") | (toUpper("A")==toUpper("a")) | (toLower("A")==toLower("a")) |
  4. +------------+------------------------------+------------------------------+
  5. | false | true | true |
  6. +------------+------------------------------+------------------------------+
  7. nebula> RETURN '2' == 2, toInteger('2') == 2;
  8. +----------+---------------------+
  9. | ("2"==2) | (toInteger("2")==2) |
  10. +----------+---------------------+
  11. | false | true |
  12. +----------+---------------------+

>

  1. nebula> RETURN 3 > 2;
  2. +-------+
  3. | (3>2) |
  4. +-------+
  5. | true |
  6. +-------+
  7. nebula> WITH 4 AS one, 3 AS two \
  8. RETURN one > two AS result;
  9. +--------+
  10. | result |
  11. +--------+
  12. | true |
  13. +--------+

>=

  1. nebula> RETURN 2 >= "2", 2 >= 2;
  2. +----------+--------+
  3. | (2>="2") | (2>=2) |
  4. +----------+--------+
  5. | __NULL__ | true |
  6. +----------+--------+

<

  1. nebula> YIELD 2.0 < 1.9;
  2. +---------+
  3. | (2<1.9) |
  4. +---------+
  5. | false |
  6. +---------+

<=

  1. nebula> YIELD 0.11 <= 0.11;
  2. +--------------+
  3. | (0.11<=0.11) |
  4. +--------------+
  5. | true |
  6. +--------------+

!=

  1. nebula> YIELD 1 != '1';
  2. +----------+
  3. | (1!="1") |
  4. +----------+
  5. | true |
  6. +----------+

IS [NOT] NULL

  1. nebula> RETURN null IS NULL AS value1, null == null AS value2, null != null AS value3;
  2. +--------+----------+----------+
  3. | value1 | value2 | value3 |
  4. +--------+----------+----------+
  5. | true | __NULL__ | __NULL__ |
  6. +--------+----------+----------+
  7. nebula> RETURN length(NULL), size(NULL), count(NULL), NULL IS NULL, NULL IS NOT NULL, sin(NULL), NULL + NULL, [1, NULL] IS NULL;
  8. +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
  9. | length(NULL) | size(NULL) | count(NULL) | NULL IS NULL | NULL IS NOT NULL | sin(NULL) | (NULL+NULL) | [1,NULL] IS NULL |
  10. +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
  11. | __NULL__ | __NULL__ | 0 | true | false | __NULL__ | __NULL__ | false |
  12. +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
  13. nebula> WITH {name: null} AS map \
  14. RETURN map.name IS NOT NULL;
  15. +----------------------+
  16. | map.name IS NOT NULL |
  17. +----------------------+
  18. | false |
  19. +----------------------+
  20. nebula> WITH {name: 'Mats', name2: 'Pontus'} AS map1, \
  21. {name: null} AS map2, {notName: 0, notName2: null } AS map3 \
  22. RETURN map1.name IS NULL, map2.name IS NOT NULL, map3.name IS NULL;
  23. +-------------------+-----------------------+-------------------+
  24. | map1.name IS NULL | map2.name IS NOT NULL | map3.name IS NULL |
  25. +-------------------+-----------------------+-------------------+
  26. | false | false | true |
  27. +-------------------+-----------------------+-------------------+
  28. nebula> MATCH (n:player) \
  29. RETURN n.age IS NULL, n.name IS NOT NULL, n.empty IS NULL;
  30. +---------------+--------------------+-----------------+
  31. | n.age IS NULL | n.name IS NOT NULL | n.empty IS NULL |
  32. +---------------+--------------------+-----------------+
  33. | false | true | true |
  34. | false | true | true |
  35. | false | true | true |
  36. +---------------+--------------------+-----------------+
  37. ...

IS [NOT] EMPTY

  1. nebula> RETURN null IS EMPTY;
  2. +---------------+
  3. | NULL IS EMPTY |
  4. +---------------+
  5. | false |
  6. +---------------+
  7. nebula> RETURN "a" IS NOT EMPTY;
  8. +------------------+
  9. | "a" IS NOT EMPTY |
  10. +------------------+
  11. | true |
  12. +------------------+
  13. nebula> GO FROM "player100" OVER * WHERE properties($$).name IS NOT EMPTY YIELD dst(edge);
  14. +-------------+
  15. | dst(EDGE) |
  16. +-------------+
  17. | "team204" |
  18. | "player101" |
  19. | "player125" |
  20. +-------------+

最后更新: November 1, 2021