Skip to content

Commit

Permalink
Cherrypick 250 (#723)
Browse files Browse the repository at this point in the history
* add cn doc (#708)

* add cn doc

* concat and show meta leader

* Update 13.concat.md

Co-authored-by: 朱晓青 <86282370+izhuxiaoqing@users.noreply.github.com>

* ldap and improve query by tag index (#711)

* ldap and improve query by tag index

* Update improve-query-by-tag-index.md

* Update 4.ldap.md

Co-authored-by: cooper-lzy <78672629+cooper-lzy@users.noreply.github.com>
  • Loading branch information
izhuxiaoqing and cooper-lzy authored Sep 14, 2021
1 parent 04a00f5 commit 32e456c
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 1 deletion.
109 changes: 109 additions & 0 deletions docs-2.0/3.ngql-guide/6.functions-and-expressions/13.concat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# concat function

The `concat()` and `concat_ws()` functions return strings concatenated by one or more strings.

## concat() function

The `concat()` function requires at least two or more strings. All the parameters are concatenated into one string.

- If there is only one string, the string itself is returned.

- If any one of the strings is `NULL`, `NULL` is returned.

### Syntax

```bash
concat(string1,string2,...)
```

### Examples

```bash
//This example concatenates 1, 2, and 3.
nebula> RETURN concat("1","2","3") AS r;
+-------+
| r |
+-------+
| "123" |
+-------+

//In this example, one of the string is NULL.
nebula> RETURN concat("1","2",NULL) AS r;
+----------+
| r |
+----------+
| __NULL__ |
+----------+

nebula> GO FROM "player100" over follow \
YIELD concat(follow._src, $^.player.age, $$.player.name, follow.degree) AS A;
+------------------------------+
| A |
+------------------------------+
| "player10042Tony Parker95" |
+------------------------------+
| "player10042Manu Ginobili95" |
+------------------------------+
```

## concat_ws() function

The `concat_ws()` function connects two or more strings with a predefined separator.

- If the separator is `NULL`, the `concat_ws()` function returns `NULL`.

- If the separator is not `NULL` and there is only one string, the string itself is returned.

- If the separator is not `NULL` and there is a `NULL` in the strings, `NULL` is ignored during the concatenation.

### Syntax

```bash
concat_ws(separator,string1,string2,... )
```

### Examples

```bash
//This example concatenates a, b, and c with the separator +.
nebula> RETURN concat_ws("+","a","b","c") AS r;
+---------+
| r |
+---------+
| "a+b+c" |
+---------+

//In this example, the separator is NULL.
neubla> RETURN concat_ws(NULL,"a","b","c") AS r;
+----------+
| r |
+----------+
| __NULL__ |
+----------+

//In this example, the separator is + and there is a NULL in the strings.
nebula> RETURN concat_ws("+","a",NULL,"b","c") AS r;
+---------+
| r |
+---------+
| "a+b+c" |
+---------+

//In this example, the separator is + and there is only one string.
nebula> RETURN concat_ws("+","a") AS r;
+-----+
| r |
+-----+
| "a" |
+-----+

nebula> GO FROM "player100" over follow \
YIELD concat_ws(" ",follow._src, $^.player.age, $$.player.name, follow.degree) AS A;
+---------------------------------+
| A |
+---------------------------------+
| "player100 42 Tony Parker 95" |
+---------------------------------+
| "player100 42 Manu Ginobili 95" |
+---------------------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SHOW META LEADER

The `SHOW META LEADER` statement shows the information of the leader in the current Meta cluster.

For more information about the Meta service, see [Meta service](../../../1.introduction/3.nebula-graph-architecture/2.meta-service.md).

## Syntax

```ngql
SHOW META LEADER;
```

## Example

```ngql
nebula> SHOW META LEADER;
+------------------+---------------------------+
| Meta Leader | secs from last heart beat |
+------------------+---------------------------+
| "127.0.0.1:9559" | 3 |
+------------------+---------------------------+
```

|Parameter|Description|
|:---|:---|
|`Meta Leader`|Shows the information of the leader in the Meta cluster, including the IP address and port of the server where the leader is located.|
|`secs from last heart beat`|Indicates the time interval since the last heartbeat. This parameter is measured in seconds.|
101 changes: 101 additions & 0 deletions docs-2.0/7.data-security/1.authentication/4.ldap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# OpenLDAP authentication

This topic introduces how to connect Nebula Graph to the OpenLDAP server and use the DN (Distinguished Name) and password defined in OpenLDAP for authentication.

!!! enterpriseonly

This feature is supported by the Enterprise Edition only.

## Authentication method

After the OpenLDAP authentication is enabled and users log into Nebula Graph with the account and password, Nebula Graph checks whether the login account exists in the Meta service. If the account exists, Nebula Graph finds the corresponding DN in OpenLDAP according to the authentication method and verifies the password.

OpenLDAP supports two authentication methods: simple bind authentication (SimpleBindAuth) and search bind authentication (SearchBindAuth).

### SimpleBindAuth

Simple bind authentication splices the login account and the configuration information of Graph services into a DN that can be recognized by OpenLDAP, and then authenticates on OpenLDAP based on the DN and password.

### SearchBindAuth

Search bind authentication reads the Graph service configuration information and queries whether the `uid` in the configuration matches the login account. If they match, search bind authentication reads the DN, and then uses the DN and password to verify on OpenLDAP.

## Prerequisites

- [OpenLDAP](https://www.openldap.org/) is installed.

- The account and password are imported on OpenLDAP.

- The server where OpenLDAP is located has opened the corresponding authentication port.

## Procedures

Take the existing account `test2` and password `passwdtest2` on OpenLDAP as an example.

1. [Connect to Nebula Graph](../../4.deployment-and-installation/connect-to-nebula-graph.md), create and authorize the shadow account `test2` corresponding to OpenLDAP.

```ngql
nebula> CREATE USER test2 WITH PASSWORD '';
nebula> GRANT ROLE ADMIN ON basketballplayer TO test2;
```

!!! note

When creating an account in Nebula Graph, the password can be set arbitrarily.

2. Edit the configuration file `nebula-graphd.conf` (The default path is`/usr/local/nebula/etc/`):

- SimpleBindAuth (Recommended)

```bash
# Whether to get the configuration information from the configuration file.
--local_config=true
# Whether to enable authentication.
--enable_authorize=true
# Authentication methods include password, ldap, and cloud.
--auth_type=ldap
# The address of the OpenLDAP server.
--ldap_server=192.168.8.211
# The port of the OpenLDAP server.
--ldap_port=389
# The name of the Schema in OpenLDAP.
--ldap_scheme=ldap
# The prefix of DN.
--ldap_prefix=uid=
# The suffix of DN.
--ldap_suffix=,ou=it,dc=sys,dc=com
```

- SearchBindAuth

```bash
# Whether to get the configuration information from the configuration file.
--local_config=true
# Whether to enable authentication.
--enable_authorize=true
# Authentication methods include password, ldap, and cloud.
--auth_type=ldap
# The address of the OpenLDAP server.
--ldap_server=192.168.8.211
# The port of the OpenLDAP server.
--ldap_port=389
# The name of the Schema in OpenLDAP.
--ldap_scheme=ldap
# The DN that binds the target.
--ldap_basedn=uid=test2,ou=it,dc=sys,dc=com
```

3. [Restart Nebula Graph services](../../4.deployment-and-installation/manage-service.md) to make the new configuration valid.

4. Run the login test.

```bash
$ ./nebula-console --addr 127.0.0.1 --port 9669 -u test2 -p passwdtest2
2021/09/08 03:49:39 [INFO] connection pool is initialized successfully
Welcome to Nebula Graph!
```

!!! note

After using OpenLDAP for authentication, local users (including `root`) cannot log in normally.
54 changes: 54 additions & 0 deletions docs-2.0/8.service-tuning/improve-query-by-tag-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Add and delete tags

OpenCypher has the features of `SET label` and `REMOVE label` to speed up the process of querying or labeling.

Nebula Graph achieves the same operations by creating and inserting tags to an existing vertex, which can quickly query vertices based on the tag name. Users can also run `DELETE TAG` to delete some vertices that are no longer needed.

!!! caution

Make sure that there is another tag on the vertex. Otherwise, the vertex will be deleted when the last tag is deleted.

## Examples

For example, in the `basketballplayer` data set, some basketball players are also team shareholders. Users can create an index for the shareholder tag `shareholder` for quick search. If the player is no longer a shareholder, users can delete the shareholder tag of the corresponding player by `DELETE TAG`.

```ngql
//This example creates the shareholder tag and index.
nebula> CREATE TAG shareholder();
nebula> CREATE TAG INDEX shareholder_tag on shareholder();
//This example adds a tag on the vertex.
nebula> INSERT VERTEX shareholder() VALUES "player100":();
nebula> INSERT VERTEX shareholder() VALUES "player101":();
//This example queries all the shareholders.
nebula> MATCH (v:shareholder) RETURN v;
+---------------------------------------------------------------------+
| v |
+---------------------------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"} :shareholder{}) |
+---------------------------------------------------------------------+
| ("player101" :player{age: 36, name: "Tony Parker"} :shareholder{}) |
+---------------------------------------------------------------------+
nebula> LOOKUP ON shareholder;
+-------------+
| VertexID |
+-------------+
| "player100" |
+-------------+
| "player101" |
+-------------+
//In this example, the "player100" is no longer a shareholder.
nebula> DELETE TAG shareholder FROM "player100";
nebula> LOOKUP ON shareholder;
+-------------+
| VertexID |
+-------------+
| "player101" |
+-------------+
```

!!! note

If the index is created after inserting the test data, use the `REBUILD TAG INDEX <index_name_list>;` statement to rebuild the index.
6 changes: 5 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ nav:
- collect(): 3.ngql-guide/6.functions-and-expressions/10.collect.md
- reduce(): 3.ngql-guide/6.functions-and-expressions/11.reduce.md
- hash(): 3.ngql-guide/6.functions-and-expressions/12.hash.md
- concat(): 3.ngql-guide/6.functions-and-expressions/13.concat.md
- Predicate functions: 3.ngql-guide/6.functions-and-expressions/8.predicate.md
- User-defined functions: 3.ngql-guide/6.functions-and-expressions/9.user-defined-functions.md

Expand Down Expand Up @@ -189,6 +190,7 @@ nav:
- SHOW USERS: 3.ngql-guide/7.general-query-statements/6.show/16.show-users.md
- SHOW SESSIONS: 3.ngql-guide/7.general-query-statements/6.show/17.show-sessions.md
- SHOW QUERIES: 3.ngql-guide/7.general-query-statements/6.show/18.show-queries.md
- SHOW META LEADER: 3.ngql-guide/7.general-query-statements/6.show/19.show-meta-leader.md

- Clauses and options:
- GROUP BY: 3.ngql-guide/8.clauses-and-options/group-by.md
Expand All @@ -214,7 +216,7 @@ nav:
- SHOW TAGS: 3.ngql-guide/10.tag-statements/4.show-tags.md
- DESCRIBE TAG: 3.ngql-guide/10.tag-statements/5.describe-tag.md
- DELETE TAG: 3.ngql-guide/10.tag-statements/6.delete-tag.md

- Edge type statements:
- CREATE EDGE: 3.ngql-guide/11.edge-type-statements/1.create-edge.md
- DROP EDGE: 3.ngql-guide/11.edge-type-statements/2.drop-edge.md
Expand Down Expand Up @@ -296,6 +298,7 @@ nav:
- Authentication: 7.data-security/1.authentication/1.authentication.md
- User management: 7.data-security/1.authentication/2.management-user.md
- Roles and privileges: 7.data-security/1.authentication/3.role-list.md
- OpenLDAP authentication: 7.data-security/1.authentication/4.ldap.md
# - Backup & Restore:
# - What is Backup & Restore: 7.data-security/2.backup-restore/1.what-is-br.md
# - Compile BR: 7.data-security/2.backup-restore/2.compile-br.md
Expand All @@ -310,6 +313,7 @@ nav:
- System design suggestions: 8.service-tuning/3.system-design.md
- Execution plan: 8.service-tuning/4.plan.md
- Processing super vertices: 8.service-tuning/super-node.md
- Add or delete tag: 8.service-tuning/improve-query-by-tag-index.md

- Client:
- Clients overview: 14.client/1.nebula-client.md
Expand Down

0 comments on commit 32e456c

Please sign in to comment.