Skip to content

Commit

Permalink
add-length()-and-size() (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
abby-cyber authored Nov 11, 2022
1 parent 1fd37bf commit 785c4f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br/>If the number is `0`, the system returns `0`.<br/>If the number is negative, the system returns `-1`.<br/>If the number is positive, the system returns `1`. |
| double e() | Returns the base of the natural logarithm, e (2.718281828459045). |
Expand Down Expand Up @@ -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. |
Expand Down
14 changes: 12 additions & 2 deletions docs-2.0/3.ngql-guide/6.functions-and-expressions/1.math.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(<expression>)`
Syntax: `size({<expression>|<string>})`

- `expression`: An expression for a list or map.
- `string`: A specified string.

- Result type: Int

Expand All @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions docs-2.0/3.ngql-guide/6.functions-and-expressions/2.string.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ nebula> RETURN upper("Basketball_Player");

length() returns the length of the given string in bytes.

Syntax: `length(<string>)`
Syntax: `length({<string>|<path>})`

- `string`: A specified string.

- `path`: A specified path represented by a variable.
- Result type: Int

Example:
Expand All @@ -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.
Expand Down

0 comments on commit 785c4f6

Please sign in to comment.