Skip to content

Commit

Permalink
[user manual] add functions and operators (vesoft-inc#688)
Browse files Browse the repository at this point in the history
* add functions and operators

* add language structure

* update table format

* update

* update

* update

* add functions and operators

* add language structure

* update table format

* Fix use-after-free problem in BalancerPlan (vesoft-inc#684)

* update

* Implement leader change logic (vesoft-inc#675)

* update

* update

* add assignment example

* add functions and operators

* add language structure

* update table format

* update

* update

* update

* add functions and operators

* update table format

* update

* update

* update

* add assignment example

* merge
  • Loading branch information
jude-zhu authored and dutor committed Jul 29, 2019
1 parent ae73b70 commit 685980a
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
| Name | Description |
|:----|:----:|
| == | Equal operator |
| > | Greater than operator |
| >= | Greater than or equal operator |
| < | Less than operator |
| <= | Less than or equal operator |
| != | Not equal operator |


Comparison operations result in a value of _true_ and _false_.

* ==

Equal. String comparisons are case-sensitive. Values of different type are not equal.

```
nebula> YIELD 'A' == 'a';
==============
| ("A"=="a") |
==============
| false |
--------------
nebula> YIELD '2' == 2;
============
| ("2"==2) |
============
| false |
------------
```

* &gt;

Greater than:

```
nebula> YIELD 3 > 2;
=========
| (3>2) |
=========
| true |
---------
```

* &ge;

Greater than or equal:

```
nebula> YIELD 2 >= 2;
==========
| (2>=2) |
==========
| true |
----------
```

* &lt;

Less than:

```
nebula> YIELD 2.0 < 1.9;
=======================
| (2.000000<1.900000) |
=======================
| false |
-----------------------
```

* &le;

Less than or equal:

```
nebula> YIELD 0.11 <= 0.11;
========================
| (0.110000<=0.110000) |
========================
| true |
------------------------
```

* !=

Not equal:

```
nebula> YIELD 1 != '1'
============
| (1!="1") |
============
| true |
------------
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
| Name | Description |
|:----|:----:|
| abs() | Return the absolute value |
| acos() | Return the arc cosine |
| asin() | Return the arc sine |
| atan() | Return the arc tangent |
| cbrt() | Returns the cubic root of the argument |
| ceil() | Return the smallest integer value not less than the argument |
| cos() | Return the cosine |
| exp() | Raise to the power of |
| floor() | Return the largest integer value not greater than the argument |
| hypot() | Returns the hypotenuse of a right-angled triangle |
| log() | Return the natural logarithm of the first argument |
| log2() | Return the base-2 logarithm of the argument |
| log10() | Return the base-10 logarithm of the argument |
| now() | Return the current date and time |
| pow() | Return the argument raised to the specified power |
| rand32() | Return a random 32 bit interger |
| rand64() | Return a random 64 bit interger |
| round() | Round the argument |
| sin() | Return the sine of the argument |
| sqrt() | Return the square root of the argument |
| strcasecmp() | Compare strings without sensitivity to case |
| tan() | Return the tangent of the argument |
48 changes: 48 additions & 0 deletions docs/manul_doc/Functions_and_Operators/Logical_Operators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
| Name | Description |
|:----|:----:|
| && | Logical AND |
| ! | Logical NOT |
| \|\| | Logical OR |


In nGQL, nonzero numbers are evaluted to _true_. The precedence of the operators refer to [Operator Precedence](./Operator_Precedence.md).

* &&

Logical AND:

```
nebula> YIELD -1 && true;
================
| (-(1)&&true) |
================
| true |
----------------
```

* !

Logical NOT:

```
nebula> YIELD !(-1);
===========
| !(-(1)) |
===========
| false |
-----------
```

* ||

Logical OR:

```
nebula> YIELD 1 || !1;
=============
| (1||!(1)) |
=============
| true |
```

22 changes: 22 additions & 0 deletions docs/manul_doc/Functions_and_Operators/Operator_Precedence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The following list shows the precedence of nGQL operators, in descending order. Operators on a line have the same precedence.

```
!
- (unary minus)
*, /, %
-, +
== , >=, >, <=, <, <>, !=
&&
||
= (assignment)
```

For operators from the same precedence level within an expression, evaluation is from left to right, with the exception that assignment evaluates right to left. However, parentheses can be used to modify the order.

Examples:

```
YIELD 2+3*5;
YIELD (2+3)*5;
```

23 changes: 23 additions & 0 deletions docs/manul_doc/Functions_and_Operators/Operators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
| Name | Description |
|:----|:----|
| && | Logical AND |
| = | Assign a value |
| \|\| | Logical OR |
| / | Division operator |
| == | Equal operator |
| != | Not equal operator |
| < | Less than operator |
| <= | Less than or equal operator |
| - | Minus operator |
| % | Modulo operator |
| + | Addition operator |
| ! | Logical NOT |
| * | Multiplication operator |
| - | Change the sign of the argument |


Example:

```
nebula> $a=GO FROM 201 OVER like; GO FROM $a.id OVER select YIELD $^.student.name;
```
1 change: 1 addition & 0 deletions docs/manul_doc/Functions_and_Operators/Type_Conversion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Not supported yet
19 changes: 19 additions & 0 deletions docs/manul_doc/Language_Structure/Identifier_Case_Sensitivity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
In Nebula Graph, Identifiers are case-sensitive.

The following statement would not work because it refers to a space both as 'my_space' and as 'MY_SPACE':

```
nebula> CREATE SPACE my_space(partition_num=1, replica_factor=1);
nebula> use MY_SPACE;
```

However, keywords and reserved words are case-insensitive.

The following statements are equivalent:
```
nebula> show spaces;
nebula> SHOW SPACES;
nebula> SHOW spaces;
nebula> show spaces;
```

9 changes: 9 additions & 0 deletions docs/manul_doc/Language_Structure/Schema_Object_Names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Certain objects within Nebula graph, including space, tag, edge, alias, customer variables and other object names are referred as identifiers. This section describes the rules for identifiers in Nebula Graph:

* Permitted characters in identifiers:

ASCII: [0-9,a-z,A-Z,_] (basic Latin letters, digits 0-9, underscore), Other punctuation characters are not supported.
* All identifiers must begin with a letter of the alphabet.
* Identifiers are case sensitive.
* You cannot use a keyword (a reserved word) as an identifier.

0 comments on commit 685980a

Please sign in to comment.