From be2e2c341d8292e747ac0afc879fbdbf20649663 Mon Sep 17 00:00:00 2001
From: Abby <78209557+abby-cyber@users.noreply.github.com>
Date: Fri, 11 Nov 2022 15:58:57 +0800
Subject: [PATCH] add-length()-and-size()
---
docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md | 4 ++--
.../6.functions-and-expressions/1.math.md | 14 ++++++++++++--
.../6.functions-and-expressions/2.string.md | 15 +++++++++++++--
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md b/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md
index 725cca1fe0b..1193bd809eb 100644
--- a/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md
+++ b/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md
@@ -31,7 +31,7 @@
| bit_and() | Bitwise AND. |
| bit_or() | Bitwise OR. |
| bit_xor() | Bitwise XOR. |
- | int size() | Returns the number of elements in a list or a map. |
+ | int size() | Returns the number of elements in a list or a map or the length of a string. |
| int range(int start, int end, int step) | Returns a list of integers from `[start,end]` in the specified steps. `step` is 1 by default. |
| int sign(double x) | Returns the signum of the given number.
If the number is `0`, the system returns `0`.
If the number is negative, the system returns `-1`.
If the number is positive, the system returns `1`. |
| double e() | Returns the base of the natural logarithm, e (2.718281828459045). |
@@ -60,7 +60,7 @@
|string toLower(string a) | The same as `lower()`. |
|string upper(string a) | Returns the argument in uppercase. |
|string toUpper(string a) | The same as `upper()`. |
- |int length(string a) | Returns the length of the given string in bytes. |
+ |int length(a) | Returns the length of the given string in bytes or the length of a path in hops. |
|string trim(string a) | Removes leading and trailing spaces. |
|string ltrim(string a) | Removes leading spaces. |
|string rtrim(string a) | Removes trailing spaces. |
diff --git a/docs-2.0/3.ngql-guide/6.functions-and-expressions/1.math.md b/docs-2.0/3.ngql-guide/6.functions-and-expressions/1.math.md
index 734f99bc5b5..6e5331a3400 100644
--- a/docs-2.0/3.ngql-guide/6.functions-and-expressions/1.math.md
+++ b/docs-2.0/3.ngql-guide/6.functions-and-expressions/1.math.md
@@ -551,11 +551,12 @@ nebula> RETURN bit_xor(5,6);
## size()
-size() returns the number of elements in a list or a map.
+size() returns the number of elements in a list or a map, or the length of a string.
-Syntax: `size()`
+Syntax: `size({|})`
- `expression`: An expression for a list or map.
+- `string`: A specified string.
- Result type: Int
@@ -570,6 +571,15 @@ nebula> RETURN size([1,2,3,4]);
+-----------------+
```
+```ngql
+nebula> RETURN size("basketballplayer") as size;
++------+
+| size |
++------+
+| 16 |
++------+
+```
+
## range()
range() returns a list of integers from `[start,end]` in the specified steps.
diff --git a/docs-2.0/3.ngql-guide/6.functions-and-expressions/2.string.md b/docs-2.0/3.ngql-guide/6.functions-and-expressions/2.string.md
index 187cea9bfc0..d02ab3e2c40 100644
--- a/docs-2.0/3.ngql-guide/6.functions-and-expressions/2.string.md
+++ b/docs-2.0/3.ngql-guide/6.functions-and-expressions/2.string.md
@@ -77,10 +77,10 @@ nebula> RETURN upper("Basketball_Player");
length() returns the length of the given string in bytes.
-Syntax: `length()`
+Syntax: `length({|})`
- `string`: A specified string.
-
+- `path`: A specified path represented by a variable.
- Result type: Int
Example:
@@ -94,6 +94,17 @@ nebula> RETURN length("basketball");
+----------------------+
```
+```ngql
+nebula> MATCH p=(v:player{name:"Tim Duncan"})-->(v2) return length(p);
++-----------+
+| length(p) |
++-----------+
+| 1 |
+| 1 |
+| 1 |
++-----------+
+```
+
## trim()
trim() removes the spaces at the leading and trailing of the string.