字符串运算符
Nebula Graph支持使用字符串运算符进行连接、搜索、匹配运算。支持的运算符如下。
名称 | 说明 |
---|---|
+ | 连接字符串。 |
CONTAINS | 在字符串中执行搜索。 |
(NOT) IN | 字符串是否匹配某个值。 |
(NOT) STARTS WITH | 在字符串的开头执行匹配。 |
(NOT) ENDS WITH | 在字符串的结尾执行匹配。 |
正则表达式 | 通过正则表达式匹配字符串。 |
示例
+
nebula> RETURN 'a' + 'b';
+-------+
| (a+b) |
+-------+
| "ab" |
+-------+
nebula> UNWIND 'a' AS a UNWIND 'b' AS b RETURN a + b;
+-------+
| (a+b) |
+-------+
| "ab" |
+-------+
CONTAINS
CONTAINS
要求待运算的左右两边都是字符串类型。
nebula> MATCH (s:player)-[e:serve]->(t:team) WHERE id(s) == "player101" \
AND t.name CONTAINS "ets" RETURN s.name, e.start_year, e.end_year, t.name;
+---------------+--------------+------------+-----------+
| s.name | e.start_year | e.end_year | t.name |
+---------------+--------------+------------+-----------+
| "Tony Parker" | 2018 | 2019 | "Hornets" |
+---------------+--------------+------------+-----------+
nebula> GO FROM "player101" OVER serve WHERE (STRING)serve.start_year CONTAINS "19" AND \
$^.player.name CONTAINS "ny" \
YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name;
+----------------+------------------+----------------+--------------+
| $^.player.name | serve.start_year | serve.end_year | $$.team.name |
+----------------+------------------+----------------+--------------+
| "Tony Parker" | 1999 | 2018 | "Spurs" |
+----------------+------------------+----------------+--------------+
nebula> GO FROM "player101" OVER serve WHERE !($$.team.name CONTAINS "ets") \
YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name;
+----------------+------------------+----------------+--------------+
| $^.player.name | serve.start_year | serve.end_year | $$.team.name |
+----------------+------------------+----------------+--------------+
| "Tony Parker" | 1999 | 2018 | "Spurs" |
+----------------+------------------+----------------+--------------+
(NOT) IN
nebula> RETURN 1 IN [1,2,3], "Yao" NOT IN ["Yi", "Tim", "Kobe"], NULL in ["Yi", "Tim", "Kobe"]
+----------------+------------------------------------+-------------------------------+
| (1 IN [1,2,3]) | ("Yao" NOT IN ["Yi","Tim","Kobe"]) | (NULL IN ["Yi","Tim","Kobe"]) |
+----------------+------------------------------------+-------------------------------+
| true | true | false |
+----------------+------------------------------------+-------------------------------+
(NOT) STARTS WITH
nebula> RETURN 'apple' STARTS WITH 'app', 'apple' STARTS WITH 'a', 'apple' STARTS WITH toUpper('a')
+-----------------------------+---------------------------+------------------------------------+
| ("apple" STARTS WITH "app") | ("apple" STARTS WITH "a") | ("apple" STARTS WITH toUpper("a")) |
+-----------------------------+---------------------------+------------------------------------+
| true | true | false |
+-----------------------------+---------------------------+------------------------------------+
nebula> RETURN 'apple' STARTS WITH 'b','apple' NOT STARTS WITH 'app'
+---------------------------+---------------------------------+
| ("apple" STARTS WITH "b") | ("apple" NOT STARTS WITH "app") |
+---------------------------+---------------------------------+
| false | false |
+---------------------------+---------------------------------+
(NOT) ENDS WITH
nebula> RETURN 'apple' ENDS WITH 'app', 'apple' ENDS WITH 'e', 'apple' ENDS WITH 'E', 'apple' ENDS WITH 'b'
+---------------------------+-------------------------+-------------------------+-------------------------+
| ("apple" ENDS WITH "app") | ("apple" ENDS WITH "e") | ("apple" ENDS WITH "E") | ("apple" ENDS WITH "b") |
+---------------------------+-------------------------+-------------------------+-------------------------+
| false | true | false | false |
+---------------------------+-------------------------+-------------------------+-------------------------+
正则表达式
Nebula Graph支持使用正则表达式进行过滤,正则表达式的语法是继承自std::regex
,用户可以使用语法=~ '<regexp>'
进行正则表达式匹配配。例如:
nebula> RETURN "384748.39" =~ "\\d+(\\.\\d{2})?";
+----------------------------+
| (384748.39=~\d+(\.\d{2})?) |
+----------------------------+
| true |
+----------------------------+
nebula> MATCH (v:player) WHERE v.name =~ 'Tony.*' RETURN v.name;
+---------------+
| v.name |
+---------------+
| "Tony Parker" |
+---------------+