From 490fb13d9a473051bc898b55d46f13bc035c579d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=99=93=E9=9D=92?= <86282370+izhuxiaoqing@users.noreply.github.com> Date: Wed, 14 Jul 2021 14:42:36 +0800 Subject: [PATCH 1/5] operators --- .../3.ngql-guide/5.operators/1.comparison.md | 131 ++++++++------ .../3.ngql-guide/5.operators/2.boolean.md | 9 +- docs-2.0/3.ngql-guide/5.operators/4.pipe.md | 33 +++- .../5.operators/5.property-reference.md | 17 +- docs-2.0/3.ngql-guide/5.operators/6.set.md | 160 ++++++------------ docs-2.0/3.ngql-guide/5.operators/7.string.md | 54 +++--- docs-2.0/3.ngql-guide/5.operators/8.list.md | 31 ++-- .../3.ngql-guide/5.operators/9.precedence.md | 24 +-- 8 files changed, 231 insertions(+), 228 deletions(-) diff --git a/docs-2.0/3.ngql-guide/5.operators/1.comparison.md b/docs-2.0/3.ngql-guide/5.operators/1.comparison.md index 5216c8feb99..cac61a6b484 100644 --- a/docs-2.0/3.ngql-guide/5.operators/1.comparison.md +++ b/docs-2.0/3.ngql-guide/5.operators/1.comparison.md @@ -1,41 +1,53 @@ # Comparison operators -| Name | Description | +Nebula Graph supports the following comparison operators. + +| Name | Description | |:----|:----:| -| `=` | Assign a value | -| `/` | Division operator | -| `==` | Equal operator | -| `!=`, `<>` | Not equal operator | -| `<` | Less than operator | -| `<=` | Less than or equal operator | -| `-` | Minus operator | -| `%` | Modulo operator | -| `+` | Addition operator | -| `*` | Multiplication operator | -| `-` | Change the sign of the argument | -| `IS NULL` | NULL check| -| `IS NOT NULL` | not NULL check | - -Comparison operations result in a value of _true_ and _false_. +| `=` | Assigns a value | +| `+` | Addition operator | +| `-` | Minus operator | +| `*` | Multiplication operator | +| `/` | Division operator | +| `==` | Equal operator | +| `!=`, `<>` | Not equal operator | +| `>` | Greater than operator | +| `>=` | Greater than or equal operator | +| `<` | Less than operator | +| `<=` | Less than or equal operator | +| `%` | Modulo operator | +| `-` | Changes the sign of the argument | +| `IS NULL` | NULL check | +| `IS NOT NULL` | Not NULL check | +| `IS EMPTY` | EMPTY check | +| `IS NOT EMPTY` | Not EMPTY check | + +The result of the comparison operation is `true` or `false`. !!! note - Comparability between values of different types is often undefined. The result could be NULL or others. + - Comparability between values of different types is often undefined. The result could be `NULL` or others. + + - `EMPTY` is currently used only for checking,and does not support functions or operations. It includes but is not limited to `GROUP BY`, `count()`, `sum()`, `max()`, `hash()`, ` collect()`, `+`, `*`. + +## OpenCypher compatibility -!!! note "OpenCypher compatibility" +- The comparison operation of `NULL` is different from openCypher. The behavior may also change. `IS [NOT] NULL` is often used with `OPTIONAL MATCH` in openCypher. But `OPTIONAL MATCH` is not supported in nGQL. - Comparing with NULL is different from openCypher. The behavior may change. `IS [NOT] NULL` is often used with `OPTIONAL MATCH`. But `OPTIONAL MATCH` is not support in nGQL. +- openCypher does not have `EMPTY`. Thus `EMPTY` is not supported in MATCH statements. -* `==` +## Examples -Equal. String comparisons are case-sensitive. Values of different types are not equal. +### `==` + +String comparisons are case-sensitive. Values of different types are not equal. !!! note - The equality operator is `==` in nGQL and is `=` in openCypher. + The equal operator is `==` in nGQL, while in openCypher it is `=`. ```ngql -nebula> RETURN 'A' == 'a', toUpper('A') == toUpper('a'), toLower('A') == toLower('a') +nebula> RETURN 'A' == 'a', toUpper('A') == toUpper('a'), toLower('A') == toLower('a'); +------------+------------------------------+------------------------------+ | ("A"=="a") | (toUpper("A")==toUpper("a")) | (toLower("A")==toLower("a")) | +------------+------------------------------+------------------------------+ @@ -50,9 +62,7 @@ nebula> RETURN '2' == 2, toInteger('2') == 2; +----------+---------------------+ ``` -* `>` - -Greater than: +### `>` ```ngql nebula> RETURN 3 > 2; @@ -62,7 +72,8 @@ nebula> RETURN 3 > 2; | true | +-------+ -nebula> WITH 4 AS one, 3 AS two RETURN one > two AS result; +nebula> WITH 4 AS one, 3 AS two \ + RETURN one > two AS result; +--------+ | result | +--------+ @@ -70,12 +81,10 @@ nebula> WITH 4 AS one, 3 AS two RETURN one > two AS result; +--------+ ``` -* `>=` - -Greater than or equal to: +### `>=` ```ngql -nebula> RETURN 2 >= "2", 2 >= 2 +nebula> RETURN 2 >= "2", 2 >= 2; +----------+--------+ | (2>="2") | (2>=2) | +----------+--------+ @@ -83,9 +92,7 @@ nebula> RETURN 2 >= "2", 2 >= 2 +----------+--------+ ``` -* `<` - -Less than: +### `<` ```ngql nebula> YIELD 2.0 < 1.9; @@ -96,9 +103,7 @@ nebula> YIELD 2.0 < 1.9; +---------+ ``` -* `<=` - -Less than or equal to: +### `<=` ```ngql nebula> YIELD 0.11 <= 0.11; @@ -109,9 +114,7 @@ nebula> YIELD 0.11 <= 0.11; +--------------+ ``` -* `!=` - -Not equal: +### `!=` ```ngql nebula> YIELD 1 != '1'; @@ -122,24 +125,25 @@ nebula> YIELD 1 != '1'; +--------+ ``` -* `IS [NOT] NULL` +### `IS [NOT] NULL` ```ngql -nebula> RETURN null IS NULL AS value1, null == null AS value2, null != null AS value3 +nebula> RETURN null IS NULL AS value1, null == null AS value2, null != null AS value3; +--------+----------+----------+ | value1 | value2 | value3 | +--------+----------+----------+ | true | __NULL__ | __NULL__ | +--------+----------+----------+ -nebula> RETURN length(NULL), size(NULL), count(NULL), NULL IS NULL, NULL IS NOT NULL, sin(NULL), NULL + NULL, [1, NULL] IS NULL +nebula> RETURN length(NULL), size(NULL), count(NULL), NULL IS NULL, NULL IS NOT NULL, sin(NULL), NULL + NULL, [1, NULL] IS NULL; +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+ -| length(NULL) | size(NULL) | COUNT(NULL) | NULL IS NULL | NULL IS NOT NULL | sin(NULL) | (NULL+NULL) | [1,NULL] IS NULL | +| length(NULL) | size(NULL) | count(NULL) | NULL IS NULL | NULL IS NOT NULL | sin(NULL) | (NULL+NULL) | [1,NULL] IS NULL | +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+ -| BAD_TYPE | __NULL__ | 0 | true | false | BAD_TYPE | __NULL__ | false | +| __NULL__ | __NULL__ | 0 | true | false | __NULL__ | __NULL__ | false | +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+ -nebula> WITH {name: null} AS map RETURN map.name IS NOT NULL +nebula> WITH {name: null} AS map \ + RETURN map.name IS NOT NULL; +----------------------+ | map.name IS NOT NULL | +----------------------+ @@ -147,15 +151,16 @@ nebula> WITH {name: null} AS map RETURN map.name IS NOT NULL +----------------------+ nebula> WITH {name: 'Mats', name2: 'Pontus'} AS map1, \ - {name: null} AS map2, {notName: 0, notName2: null } AS map3 \ - RETURN map1.name IS NULL, map2.name IS NOT NULL, map3.name IS NULL + {name: null} AS map2, {notName: 0, notName2: null } AS map3 \ + RETURN map1.name IS NULL, map2.name IS NOT NULL, map3.name IS NULL; +-------------------+-----------------------+-------------------+ | map1.name IS NULL | map2.name IS NOT NULL | map3.name IS NULL | +-------------------+-----------------------+-------------------+ | false | false | true | +-------------------+-----------------------+-------------------+ -nebula> MATCH (n:player) RETURN n.age IS NULL, n.name IS NOT NULL, n.empty IS NULL +nebula> MATCH (n:player) \ + RETURN n.age IS NULL, n.name IS NOT NULL, n.empty IS NULL; +---------------+--------------------+-----------------+ | n.age IS NULL | n.name IS NOT NULL | n.empty IS NULL | +---------------+--------------------+-----------------+ @@ -167,3 +172,31 @@ nebula> MATCH (n:player) RETURN n.age IS NULL, n.name IS NOT NULL, n.empty IS NU +---------------+--------------------+-----------------+ ... ``` + +### `IS [NOT] EMPTY` + +```ngql +nebula> RETURN null IS EMPTY; ++---------------+ +| NULL IS EMPTY | ++---------------+ +| false | ++---------------+ + +nebula> RETURN "a" IS NOT EMPTY; ++------------------+ +| "a" IS NOT EMPTY | ++------------------+ +| true | ++------------------+ + +nebula> GO FROM "player100" OVER * WHERE $$.player.name IS NOT EMPTY YIELD follow._dst; ++-------------+ +| follow._dst | ++-------------+ +| "player125" | ++-------------+ +| "player101" | ++-------------+ + +``` diff --git a/docs-2.0/3.ngql-guide/5.operators/2.boolean.md b/docs-2.0/3.ngql-guide/5.operators/2.boolean.md index d25ce7541a2..ef14d02e155 100644 --- a/docs-2.0/3.ngql-guide/5.operators/2.boolean.md +++ b/docs-2.0/3.ngql-guide/5.operators/2.boolean.md @@ -1,6 +1,8 @@ # Boolean operators -| **Name** | **Description** | +Nebula Graph supports the following boolean operators. + +| Name | Description | | :------- | :-------------: | | AND | Logical AND | | NOT | Logical NOT | @@ -9,9 +11,8 @@ For the precedence of the operators, refer to [Operator Precedence](9.precedence.md). -For the logical operations with NULL, refer to [NULL](../3.data-types/5.null.md). +For the logical operations with `NULL`, refer to [NULL](../3.data-types/5.null.md). ## Legacy version compatibility -* In Nebula Graph 1.0, non-zero numbers are evaluated to _true_ like c-language. -* In Nebula Graph 2.0, non-zero numbers can't be converted to boolean values. +* In Nebula Graph 2.0, non-zero numbers cannot be converted to boolean values. diff --git a/docs-2.0/3.ngql-guide/5.operators/4.pipe.md b/docs-2.0/3.ngql-guide/5.operators/4.pipe.md index 9c0d9a59a23..575624ed736 100644 --- a/docs-2.0/3.ngql-guide/5.operators/4.pipe.md +++ b/docs-2.0/3.ngql-guide/5.operators/4.pipe.md @@ -1,21 +1,24 @@ -# Pipe operator +# Pipe operators + +Multiple queries can be combined using pipe operators in nGQL. ## OpenCypher compatibility -This page applies to native nGQL only. +Pipe operators apply to native nGQL only. ## Syntax One major difference between nGQL and SQL is how sub-queries are composed. -In SQL, to form a statement, sub-queries are nested (embedded). -In nGQL the shell style `PIPE (|)` is introduced. +- In SQL, sub-queries are nested in the query statements. + +- In nGQL, the shell style `PIPE (|)` is introduced into the sub-queries. ## Examples ```ngql nebula> GO FROM "player100" OVER follow \ -YIELD follow._dst AS dstid, $$.player.name AS Name |\ +YIELD follow._dst AS dstid, $$.player.name AS Name | \ GO FROM $-.dstid OVER follow; +-------------+ @@ -28,3 +31,23 @@ GO FROM $-.dstid OVER follow; If there is no `YIELD` clause to define the output, the destination vertex ID is returned by default. If a YIELD clause is applied, the output is defined by the YIELD clause. You must define aliases in the `YIELD` clause for the reference operator `$-` to use, just like `$-.dstid` in the preceding example. + +## Performance tips + +In Nebula Graph {{ nebula.release }}, pipes will affect the performance. Take `A | B` as an example, the effects are as follows: + +1. Pipe operators operate synchronously. That is, the data can enter the pipe clause as a whole after the execution of clause `A` before the pipe operator is completed. + +2. Pipe operators need to be serialized and deserialized, which is executed in a single thread. + +3. If `A` sends a large amount of data to `|`, the entire query request may be very slow. You can try to split this statement. + + 1. Send `A` on the application, + + 2. Split the return results on the application, + + 3. Send multiple graphd processes concurrently, + + 4. Every graphd process executes part of B. + + This is usually much faster than executing a complete `A | B` with a single graphd process. \ No newline at end of file diff --git a/docs-2.0/3.ngql-guide/5.operators/5.property-reference.md b/docs-2.0/3.ngql-guide/5.operators/5.property-reference.md index c8f4924ee90..7636c079fe8 100644 --- a/docs-2.0/3.ngql-guide/5.operators/5.property-reference.md +++ b/docs-2.0/3.ngql-guide/5.operators/5.property-reference.md @@ -1,10 +1,10 @@ # Reference operators -NGQL provides reference operators to represent a property in a `WHERE` or `YIELD` clause, or the output of the statement before the pipe symbol in a composite query. +NGQL provides reference operators to represent a property in a `WHERE` or `YIELD` clause, or the output of the statement before the pipe operator in a composite query. ## OpenCypher compatibility -This page applies to native nGQL only. +Reference operators apply to native nGQL only. ## Reference operator List @@ -12,15 +12,13 @@ This page applies to native nGQL only. |-|-| |`$^`|Refers to a source vertex property. For more information, see [Property reference](../4.variable-and-composite-queries/3.property-reference.md).| |`$$`|Refers to a destination vertex property. For more information, see [Property reference](../4.variable-and-composite-queries/3.property-reference.md).| -|`$-`|Refers to the output of the statement before the pipe symbol in a composite query. For more information, see [Pipe](4.pipe.md).| +|`$-`|Refers to the output of the statement before the pipe operator in a composite query. For more information, see [Pipe](4.pipe.md).| ## Examples -The following example returns the age of the source vertex and the destination vertex. - ```ngql -nebula> GO FROM "player100" OVER follow \ - YIELD $^.player.age AS SrcAge, $$.player.age AS DestAge; +# The following example returns the age of the source vertex and the destination vertex. +nebula> GO FROM "player100" OVER follow YIELD $^.player.age AS SrcAge, $$.player.age AS DestAge; +--------+---------+ | SrcAge | DestAge | +--------+---------+ @@ -28,11 +26,8 @@ nebula> GO FROM "player100" OVER follow \ +--------+---------+ | 42 | 41 | +--------+---------+ -``` -The following example returns the name and team of the players that "player100" follows. - -```ngql +# The following example returns the name and team of the players that player100 follows. nebula> GO FROM "player100" OVER follow \ YIELD follow._dst AS id | \ GO FROM $-.id OVER serve \ diff --git a/docs-2.0/3.ngql-guide/5.operators/6.set.md b/docs-2.0/3.ngql-guide/5.operators/6.set.md index f72fefeb5d9..cf2e1963661 100644 --- a/docs-2.0/3.ngql-guide/5.operators/6.set.md +++ b/docs-2.0/3.ngql-guide/5.operators/6.set.md @@ -1,16 +1,12 @@ -# Set operations +# Set operators -## OpenCypher compatibility - -This page applies to native nGQL only. +This topic will describe the set operators, including `UNION`, `UNION ALL`, `INTERSECT`, and `MINUS`. To combine multiple queries, use these set operators. -## Syntax +All set operators have equal precedence. If a nGQL statement contains multiple set operators, Nebula Graph will evaluate them from left to right unless parentheses explicitly specify another order. -This document descriptions the set operations, including `UNION`, `UNION ALL`, `INTERSECT`, and `MINUS`. To combine multiple queries, use the set operators. - -All set operators have equal precedence. If a nGQL statement contains multiple set operators, Nebula Graph evaluates them from the left to right unless parentheses explicitly specify another order. +## OpenCypher compatibility -To use the set operators, always match the return results of the `GO` clause with the same number and data type. +Set operators apply to native nGQL only. ## UNION, UNION DISTINCT, and UNION ALL @@ -18,17 +14,16 @@ To use the set operators, always match the return results of the `GO` clause wit UNION [DISTINCT | ALL] [ UNION [DISTINCT | ALL] ...] ``` -Operator `UNION DISTINCT` (or by short `UNION`) returns the union of two sets A and B without the duplicate elements. +- Operator `UNION DISTINCT` (or by short `UNION`) returns the union of two sets A and B without duplicated elements. -Operator `UNION ALL` returns the union of two sets A and B with duplicated elements. +- Operator `UNION ALL` returns the union of two sets A and B with duplicated elements. -The `` and `` must have the same number of columns and data types. Different data types are converted according to the [Type Conversion](../3.data-types/9.type-conversion.md). +- The `` and `` must have the same number of columns and data types. Different data types are converted according to the [Type Conversion](../3.data-types/9.type-conversion.md). -### Example - -The following statement +### Examples ```ngql +# The following statement returns the union of two query results without duplicated elements. nebula> GO FROM "player102" OVER follow \ UNION \ GO FROM "player100" OVER follow; @@ -39,13 +34,8 @@ nebula> GO FROM "player102" OVER follow \ +-------------+ | "player102" | +-------------+ -``` -returns the neighbors' id of vertex `"player102"` and `"player100` (along with edge `follow`) without duplication. - -While - -```ngql +# The following statement returns the union of two query results with duplicated elements. nebula> GO FROM "player102" OVER follow \ UNION ALL \ GO FROM "player100" OVER follow; @@ -58,77 +48,43 @@ nebula> GO FROM "player102" OVER follow \ +-------------+ | "player102" | +-------------+ -``` -returns all the neighbors of vertex `"player102"` and `"player100`, with all possible duplications. - -`UNION` can also work with the `YIELD` statement. For example, let's suppose the results of the following two queries. - -```ngql -nebula> GO FROM "player102" OVER follow YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age; -- query 1 - -+-------------+--------+-----+ -| id | Degree | Age | -+-------------+--------+-----+ -| "player101" | 75 | 36 | -- line 1 -+-------------+--------+-----+ - -nebula> GO FROM "player100" OVER follow YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age; -- query 2 - -+-------------+--------+-----+ -| id | Degree | Age | -+-------------+--------+-----+ -| "player101" | 96 | 36 | -- line 2 -+-------------+--------+-----+ -| "player102" | 90 | 33 | -- line 3 -+-------------+--------+-----+ -``` - -And the following statement -```ngql -nebula> GO FROM "player102" OVER follow YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age \ - UNION /* DISTINCT */ \ - GO FROM "player100" OVER follow YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age; -``` - -returns the follows: - -```ngql +# UNION can also work with the YIELD statement. The DISTINCT will check duplication by all the columns for every line, and remove duplicated lines if every column is the same. +nebula> GO FROM "player102" OVER follow \ + YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age \ + UNION /* DISTINCT */ \ + GO FROM "player100" OVER follow \ + YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age; +-------------+--------+-----+ | id | Degree | Age | +-------------+--------+-----+ -| "player101" | 75 | 36 | -- line 1 +| "player101" | 75 | 36 | +-------------+--------+-----+ -| "player101" | 96 | 36 | -- line 2 +| "player101" | 96 | 36 | +-------------+--------+-----+ -| "player102" | 90 | 33 | -- line 3 +| "player102" | 90 | 33 | +-------------+--------+-----+ ``` -The `DISTINCT` check duplication by all the columns for every line. So line 1 and line 2 are different. - ## INTERSECT ```ngql INTERSECT ``` -Operator `INTERSECT` returns the intersection of two sets A and B (denoted by A ⋂ B). +- Operator `INTERSECT` returns the intersection of two sets A and B (denoted by A ⋂ B). -Similar to `UNION`, the `` and `` must have the same number of columns and data types. Only the `INTERSECT` columns of `` and `` are returned. +- Similar to `UNION`, the `left` and `right` must have the same number of columns and data types. Different data types are converted according to the [Type Conversion](../3.data-types/9.type-conversion.md). -For example, the following query - -```ngql -nebula> GO FROM "player102" OVER follow YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age \ -INTERSECT \ -GO FROM "player100" OVER follow YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age; -``` - -returns +### Example ```ngql -Empty set (time spent 5194/6264 us) +nebula> GO FROM "player102" OVER follow \ + YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age \ + INTERSECT \ + GO FROM "player100" OVER follow \ + YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age; +Empty set (time spent 2990/3511 us) ``` ## MINUS @@ -137,51 +93,39 @@ Empty set (time spent 5194/6264 us) MINUS ``` -Operator `MINUS` returns the subtraction (or difference) of two sets A and B (denoted by A - B). Always pay attention to the order of the `` and ``. The set A - B consists of elements that are in A but not in B. +Operator `MINUS` returns the subtraction (or difference) of two sets A and B (denoted by `A-B`). Always pay attention to the order of the `left` and `right`. The set `A-B` consists of elements that are in A but not in B. -For example, the following query +### Example ```ngql nebula> GO FROM "player100" OVER follow \ -MINUS \ -GO FROM "player102" OVER follow; -``` - -returns - -```ngql + MINUS \ + GO FROM "player102" OVER follow; +-------------+ | follow._dst | +-------------+ | "player102" | +-------------+ -``` - -If you reverse the `MINUS` order, the query -```ngql nebula> GO FROM "player102" OVER follow \ -MINUS \ -GO FROM "player100" OVER follow; -``` - -returns - -```ngql + MINUS \ + GO FROM "player100" OVER follow; Empty set (time spent 2243/3259 us) ``` -## Precedence of the SET Operations and Pipe +## Precedence of the set operators and pipe operators -Please note that when a query contains pipe `|` and set operations, pipe takes precedence. Refer to the [Pipe Doc](../5.operators/4.pipe.md) for details. Query `GO FROM 1 UNION GO FROM 2 | GO FROM 3` is the same as query `GO FROM 1 UNION (GO FROM 2 | GO FROM 3)`. +Please note that when a query contains a pipe `|` and a set operator, the pipe takes precedence. Refer to [Pipe](../5.operators/4.pipe.md) for details. The query `GO FROM 1 UNION GO FROM 2 | GO FROM 3` is the same as the query `GO FROM 1 UNION (GO FROM 2 | GO FROM 3)`. -For example: +### Examples ```ngql -nebula> GO FROM "player102" OVER follow YIELD follow._dst AS play_dst \ -UNION \ -GO FROM "team200" OVER serve REVERSELY YIELD serve._dst AS play_dst \ -| GO FROM $-.play_dst OVER follow YIELD follow._dst AS play_dst; +nebula> GO FROM "player102" OVER follow \ + YIELD follow._dst AS play_dst \ + UNION \ + GO FROM "team200" OVER serve REVERSELY \ + YIELD serve._dst AS play_dst \ + | GO FROM $-.play_dst OVER follow YIELD follow._dst AS play_dst; +-------------+ | play_dst | @@ -194,13 +138,17 @@ GO FROM "team200" OVER serve REVERSELY YIELD serve._dst AS play_dst \ ![image](https://user-images.githubusercontent.com/42762957/97955863-3a213000-1de2-11eb-8de3-2c78da30747c.png) -The statements in the red bar are executed first. And then the statement in the green box is executed. +The above query executes the statements in the red bar first and then executes the statement in the green box. + +The parentheses can change the execution priority. For example: ```ngql -nebula> (GO FROM "player102" OVER follow YIELD follow._dst AS play_dst \ -UNION \ -GO FROM "team200" OVER serve REVERSELY YIELD serve._dst AS play_dst) \ -| GO FROM $-.play_dst OVER follow YIELD follow._dst AS play_dst; +nebula> (GO FROM "player102" OVER follow \ + YIELD follow._dst AS play_dst \ + UNION \ + GO FROM "team200" OVER serve REVERSELY \ + YIELD serve._dst AS play_dst) \ + | GO FROM $-.play_dst OVER follow YIELD follow._dst AS play_dst; ``` -In the above query, the parentheses change the execution priority, and the statements within the parentheses take the precedence. +In the above query, the statements within the parentheses take precedence. That is, the `UNION` operation will be executed first, and its output will be executed as the input of the next operation with pipes. diff --git a/docs-2.0/3.ngql-guide/5.operators/7.string.md b/docs-2.0/3.ngql-guide/5.operators/7.string.md index 771fa4f7e44..f0b053181f4 100644 --- a/docs-2.0/3.ngql-guide/5.operators/7.string.md +++ b/docs-2.0/3.ngql-guide/5.operators/7.string.md @@ -1,21 +1,23 @@ # String operators +You can use the following string operators for concatenating, querying, and matching. + | Name | Description | -|:----- | :------------------: | -| + | concatenating strings | -| CONTAINS | Perform case-sensitive inclusion searching in strings | -(NOT) IN | Whether a value is within a set of values -(NOT) STARTS WITH | Perform case-sensitive matching on the beginning of a string -(NOT) ENDS WITH | Perform case-sensitive matching on the ending of a string -Regular expressions | Perform regular expression matching on a string +|:----- | :------------------ | +| + | Concatenates strings. | +| CONTAINS | Performs searchings in strings. | +| (NOT) IN | Checks whether a value is within a set of values. | +| (NOT) STARTS WITH | Performs matchings at the beginning of a string. | +| (NOT) ENDS WITH | Performs matchings at the end of a string. | +| Regular expressions | Perform string matchings using regular expressions. | !!! note - All the string matchings are case-sensitive. + All the string searchings or matchings are case-sensitive. ## Examples -* concatenation (+) +### `+` ```ngql nebula> RETURN 'a' + 'b'; @@ -32,9 +34,9 @@ nebula> UNWIND 'a' AS a UNWIND 'b' AS b RETURN a + b; +-------+ ``` -* CONTAINS +### `CONTAINS` -The `CONTAINS` operator requires string type in both left and right side. +The `CONTAINS` operator requires string types on both left and right sides. ```ngql nebula> MATCH (s:player)-[e:serve]->(t:team) WHERE id(s) == "player101" \ @@ -63,18 +65,18 @@ nebula> GO FROM "player101" OVER serve WHERE !($$.team.name CONTAINS "ets") \ +----------------+------------------+----------------+--------------+ ``` -* IN +### `(NOT) IN` ```ngql -nebula> RETURN 1 IN [1,2,3], "Yao" IN ["Yi", "Tim", "Kobe"], NULL in ["Yi", "Tim", "Kobe"] -+----------------+--------------------------------+-------------------------------+ -| (1 IN [1,2,3]) | ("Yao" IN ["Yi","Tim","Kobe"]) | (NULL IN ["Yi","Tim","Kobe"]) | -+----------------+--------------------------------+-------------------------------+ -| true | false | false | -+----------------+--------------------------------+-------------------------------+ +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 +### `(NOT) STARTS WITH` ```ngql nebula> RETURN 'apple' STARTS WITH 'app', 'apple' STARTS WITH 'a', 'apple' STARTS WITH toUpper('a') @@ -92,7 +94,7 @@ nebula> RETURN 'apple' STARTS WITH 'b','apple' NOT STARTS WITH 'app' +---------------------------+---------------------------------+ ``` -* (NOT) ENDS WITH +### `(NOT) ENDS WITH` ```ngql nebula> RETURN 'apple' ENDS WITH 'app', 'apple' ENDS WITH 'e', 'apple' ENDS WITH 'E', 'apple' ENDS WITH 'b' @@ -103,7 +105,11 @@ nebula> RETURN 'apple' ENDS WITH 'app', 'apple' ENDS WITH 'e', 'apple' ENDS WITH +---------------------------+-------------------------+-------------------------+-------------------------+ ``` -* Regular expressions +### Regular expressions + +!!! note + + Regular expressions cannot work with native nGQL statements (`GO`, `FETCH`, `LOOKUP`, etc.). Use it in openCypher only (`MATCH`, `WHERE`, etc.). Nebula Graph supports filtering by using regular expressions. The regular expression syntax is inherited from `std::regex`. You can match on regular expressions by using `=~ 'regexp'`. For example: @@ -114,9 +120,7 @@ nebula> RETURN "384748.39" =~ "\\d+(\\.\\d{2})?"; +----------------------------+ | true | +----------------------------+ -``` -```ngql nebula> MATCH (v:player) WHERE v.name =~ 'Tony.*' RETURN v.name; +---------------+ | v.name | @@ -124,7 +128,3 @@ nebula> MATCH (v:player) WHERE v.name =~ 'Tony.*' RETURN v.name; | "Tony Parker" | +---------------+ ``` - -!!! note - - Regular expressions **CAN NOT** work with native nGQL (GO/FETCH clause will return syntax error). Use it in openCypher only (e.g., in MATCH-WHERE clause). diff --git a/docs-2.0/3.ngql-guide/5.operators/8.list.md b/docs-2.0/3.ngql-guide/5.operators/8.list.md index e7d2f476e79..75701243f3c 100644 --- a/docs-2.0/3.ngql-guide/5.operators/8.list.md +++ b/docs-2.0/3.ngql-guide/5.operators/8.list.md @@ -1,29 +1,31 @@ # List operators -List operators are: +Nebula Graph supports the following list operators: -- concatenating lists: `+` -- checking if an element exists in a list: `IN` -- accessing an element(s) in a list using the subscript operator: `[]` +|List operator|Description| +|:-----|:------------------| +| + | Concatenates lists. | +| IN | Checks if an element exists in a list. | +|[] | Accesses an element(s) in a list using the index operator. | ## Examples ```ngql -nebula> YIELD [1,2,3,4,5]+[6,7] AS myList +nebula> YIELD [1,2,3,4,5]+[6,7] AS myList; +-----------------------+ | myList | +-----------------------+ | [1, 2, 3, 4, 5, 6, 7] | +-----------------------+ -nebula> RETURN size([NULL, 1, 2]) +nebula> RETURN size([NULL, 1, 2]); +------------------+ | size([NULL,1,2]) | +------------------+ | 3 | +------------------+ -nebula> RETURN NULL IN [NULL, 1] +nebula> RETURN NULL IN [NULL, 1]; +--------------------+ | (NULL IN [NULL,1]) | +--------------------+ @@ -34,7 +36,7 @@ nebula> WITH [2, 3, 4, 5] AS numberlist \ UNWIND numberlist AS number \ WITH number \ WHERE number IN [2, 3, 8] \ - RETURN number + RETURN number; +--------+ | number | +--------+ @@ -42,10 +44,11 @@ nebula> WITH [2, 3, 4, 5] AS numberlist \ +--------+ | 3 | +--------+ -``` - - \ No newline at end of file +nebula> WITH ['Anne', 'John', 'Bill', 'Diane', 'Eve'] AS names RETURN names[1] AS result; ++--------+ +| result | ++--------+ +| "John" | ++--------+ +``` diff --git a/docs-2.0/3.ngql-guide/5.operators/9.precedence.md b/docs-2.0/3.ngql-guide/5.operators/9.precedence.md index d729c9b4e3b..7b73ec9fef4 100644 --- a/docs-2.0/3.ngql-guide/5.operators/9.precedence.md +++ b/docs-2.0/3.ngql-guide/5.operators/9.precedence.md @@ -2,20 +2,19 @@ The following list shows the precedence of nGQL operators in descending order. Operators that are shown together on a line have the same precedence. -```ngql -- (negative number) -!, NOT -*, /, % --, + -== , >=, >, <=, <, <>, != -AND -OR, XOR -= (assignment) -``` + +- `-`(negative number) +- `!`, `NOT` +- `*`, `/`, `%` +- `-`, `+` +- `==`, `>=`, `>`, `<=`, `<`, `<>`, `!=` +- `AND` +- `OR`, `XOR` +- `=` (assignment) For operators that occur at the same precedence level within an expression, evaluation proceeds left to right, with the exception that assignments evaluate right to left. -The precedence of operators determines the order of evaluation of terms in an expression. To override this order and group terms explicitly, use parentheses. +The precedence of operators determines the order of evaluation of terms in an expression. To modify this order and group terms explicitly, use parentheses. ## Examples @@ -38,4 +37,5 @@ nebula> RETURN (2+3)*5; ## OpenCypher compatibility In openCypher, comparisons can be chained arbitrarily, e.g., `x < y <= z` is equivalent to `x < y AND y <= z` in openCypher. -But in nGQL, it is equivalent to `(x < y) <= z`, which is a boolean (x < y) compare again an integer (z). And the result is NULL. + +But in nGQL, `x < y <= z` is equivalent to `(x < y) <= z`. The result of `(x < y)` is a boolean. Compare it with an integer `z`, and you will get the final result `NULL`. From 5b05029f53f7df35b44a5317dc843ea6c71dc854 Mon Sep 17 00:00:00 2001 From: randomJoe211 <69501902+randomJoe211@users.noreply.github.com> Date: Thu, 15 Jul 2021 11:41:41 +0800 Subject: [PATCH 2/5] Update docs-2.0/3.ngql-guide/5.operators/1.comparison.md --- docs-2.0/3.ngql-guide/5.operators/1.comparison.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-2.0/3.ngql-guide/5.operators/1.comparison.md b/docs-2.0/3.ngql-guide/5.operators/1.comparison.md index cac61a6b484..99c047b3a90 100644 --- a/docs-2.0/3.ngql-guide/5.operators/1.comparison.md +++ b/docs-2.0/3.ngql-guide/5.operators/1.comparison.md @@ -28,7 +28,7 @@ The result of the comparison operation is `true` or `false`. - Comparability between values of different types is often undefined. The result could be `NULL` or others. - - `EMPTY` is currently used only for checking,and does not support functions or operations. It includes but is not limited to `GROUP BY`, `count()`, `sum()`, `max()`, `hash()`, ` collect()`, `+`, `*`. + - `EMPTY` is currently used only for checking,and does not support functions or operations such as `GROUP BY`, `count()`, `sum()`, `max()`, `hash()`, ` collect()`, `+` or `*`. ## OpenCypher compatibility From 55e3ff547e63c73ece9e232601a01723bfe56e05 Mon Sep 17 00:00:00 2001 From: randomJoe211 <69501902+randomJoe211@users.noreply.github.com> Date: Thu, 15 Jul 2021 11:41:48 +0800 Subject: [PATCH 3/5] Update docs-2.0/3.ngql-guide/5.operators/6.set.md --- docs-2.0/3.ngql-guide/5.operators/6.set.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-2.0/3.ngql-guide/5.operators/6.set.md b/docs-2.0/3.ngql-guide/5.operators/6.set.md index cf2e1963661..a2d35120f0e 100644 --- a/docs-2.0/3.ngql-guide/5.operators/6.set.md +++ b/docs-2.0/3.ngql-guide/5.operators/6.set.md @@ -49,7 +49,7 @@ nebula> GO FROM "player102" OVER follow \ | "player102" | +-------------+ -# UNION can also work with the YIELD statement. The DISTINCT will check duplication by all the columns for every line, and remove duplicated lines if every column is the same. +# UNION can also work with the YIELD statement. The DISTINCT keyword will check duplication by all the columns for every line, and remove duplicated lines if every column is the same. nebula> GO FROM "player102" OVER follow \ YIELD follow._dst AS id, follow.degree AS Degree, $$.player.age AS Age \ UNION /* DISTINCT */ \ From fcd75d411b7dbcb6d5a72ed00809183f5b7abe23 Mon Sep 17 00:00:00 2001 From: randomJoe211 <69501902+randomJoe211@users.noreply.github.com> Date: Thu, 15 Jul 2021 11:41:54 +0800 Subject: [PATCH 4/5] Update docs-2.0/3.ngql-guide/5.operators/6.set.md --- docs-2.0/3.ngql-guide/5.operators/6.set.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-2.0/3.ngql-guide/5.operators/6.set.md b/docs-2.0/3.ngql-guide/5.operators/6.set.md index a2d35120f0e..15f9cd7e68f 100644 --- a/docs-2.0/3.ngql-guide/5.operators/6.set.md +++ b/docs-2.0/3.ngql-guide/5.operators/6.set.md @@ -93,7 +93,7 @@ Empty set (time spent 2990/3511 us) MINUS ``` -Operator `MINUS` returns the subtraction (or difference) of two sets A and B (denoted by `A-B`). Always pay attention to the order of the `left` and `right`. The set `A-B` consists of elements that are in A but not in B. +Operator `MINUS` returns the subtraction (or difference) of two sets A and B (denoted by `A-B`). Always pay attention to the order of `left` and `right`. The set `A-B` consists of elements that are in A but not in B. ### Example From f6c0225e186301b790eb2a6a6afebff9fadb052d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=99=93=E9=9D=92?= <86282370+izhuxiaoqing@users.noreply.github.com> Date: Fri, 16 Jul 2021 13:39:31 +0800 Subject: [PATCH 5/5] Address Wum's comments --- docs-2.0/3.ngql-guide/5.operators/4.pipe.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs-2.0/3.ngql-guide/5.operators/4.pipe.md b/docs-2.0/3.ngql-guide/5.operators/4.pipe.md index 575624ed736..61f1441363c 100644 --- a/docs-2.0/3.ngql-guide/5.operators/4.pipe.md +++ b/docs-2.0/3.ngql-guide/5.operators/4.pipe.md @@ -42,11 +42,11 @@ In Nebula Graph {{ nebula.release }}, pipes will affect the performance. Take `A 3. If `A` sends a large amount of data to `|`, the entire query request may be very slow. You can try to split this statement. - 1. Send `A` on the application, + 1. Send `A` from the application, 2. Split the return results on the application, - 3. Send multiple graphd processes concurrently, + 3. Send to multiple graphd processes concurrently, 4. Every graphd process executes part of B.