Skip to content

Commit 7ca5f44

Browse files
dl2394paradigmdenglong
authored
feat: support create/alter/drop user statement (#3678)
* feat: add Encrypt * feat: add sql node * feat: auth in sdk * fix: fix test * fix: fix bugs * test: add case * feat: hide password in terminal * feat: update sdk * fix: fix test * feat: add user in spark * fix: fix python * docs: add doc * fix: skip python test * fix: fix comment * fix: revert HandleDelete * feat: add user to openmldb-import * fix: fix alter root password --------- Co-authored-by: 4paradigm <4paradigm@denglong.local> Co-authored-by: denglong <denglong@node-4.sg.4pd.io>
1 parent 7d755ff commit 7ca5f44

File tree

71 files changed

+1421
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1421
-319
lines changed

cases/plan/alter.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2021 4Paradigm
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cases:
16+
- id: alter_user
17+
desc: alter user
18+
sql: |
19+
alter user root set options(password="123456");
20+
expect:
21+
node_tree_str: |
22+
+-node[kAlterUserStmt]
23+
+-if_exists: false
24+
+-user: root
25+
+-options:
26+
+-password:
27+
+-expr[primary]
28+
+-value: 123456
29+
+-type: string
30+
31+
- id: alter_user_if_exist
32+
desc: alter user
33+
sql: |
34+
alter user if exists root set options(password="123456");
35+
expect:
36+
node_tree_str: |
37+
+-node[kAlterUserStmt]
38+
+-if_exists: true
39+
+-user: root
40+
+-options:
41+
+-password:
42+
+-expr[primary]
43+
+-value: 123456
44+
+-type: string

cases/plan/cmd.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ cases:
189189
+-cmd_type: drop database
190190
+-if_exists: true
191191
+-args: [db1]
192+
- id: drop_user
193+
desc: DROP USER IF EXISTS
194+
sql: DROP USER IF EXISTS user1
195+
expect:
196+
node_tree_str: |
197+
+-node[CMD]
198+
+-cmd_type: drop user
199+
+-if_exists: true
200+
+-args: [user1]
201+
- id: drop_user_1
202+
desc: DROP USER
203+
sql: DROP USER user1
204+
expect:
205+
node_tree_str: |
206+
+-node[CMD]
207+
+-cmd_type: drop user
208+
+-args: [user1]
192209
- id: show_deployments
193210
desc: show deployments
194211
sql: SHOW DEPLOYMENTS;

cases/plan/create.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ cases:
10251025
+-0:
10261026
+-node[kCompressType]
10271027
+-compress_type: snappy
1028+
10281029
- id: 35
10291030
desc: Create table with array & map type
10301031
sql: |
@@ -1067,3 +1068,40 @@ cases:
10671068
| +-column_name: attrs
10681069
| +-column_type: map<string, int32 NOT NULL> NOT NULL
10691070
+-table_option_list: []
1071+
1072+
- id: 36
1073+
desc: create user
1074+
sql: |
1075+
create user root;
1076+
expect:
1077+
node_tree_str: |
1078+
+-node[kCreateUserStmt]
1079+
+-if_not_exists: false
1080+
+-user: root
1081+
+-options: <nil>
1082+
1083+
- id: 37
1084+
desc: create user if not exist
1085+
sql: |
1086+
create user if not exists root;
1087+
expect:
1088+
node_tree_str: |
1089+
+-node[kCreateUserStmt]
1090+
+-if_not_exists: true
1091+
+-user: root
1092+
+-options: <nil>
1093+
1094+
- id: create_user_passwd
1095+
desc: create user with password
1096+
sql: |
1097+
create user root OPTIONS (password="123456");
1098+
expect:
1099+
node_tree_str: |
1100+
+-node[kCreateUserStmt]
1101+
+-if_not_exists: false
1102+
+-user: root
1103+
+-options:
1104+
+-password:
1105+
+-expr[primary]
1106+
+-value: 123456
1107+
+-type: string

docs/en/deploy/install_deploy.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ cp conf/apiserver.flags.template conf/apiserver.flags
560560
* Modify the `endpoint`. The `endpoint` consists of a colon-separated deployment machine IP/domain name and port number (endpoints cannot use 0.0.0.0 and 127.0.0.1, and must be a public IP).
561561
* Modify `zk_cluster` to point to the address of the ZooKeeper service that has already been started (see [Deploy ZooKeeper - 4. ZooKeeper Service Address and Connection Test](zookeeper_addr)). If the ZooKeeper service is a cluster, separate the addresses with commas, for example, `172.27.128.33:7181,172.27.128.32:7181,172.27.128.31:7181`.
562562
* Modify `zk_root_path`. In this example, `/openmldb_cluster` is used. Note that **components under the same cluster share the same `zk_root_path`**. So in this deployment, the `zk_root_path` for each component's configuration is `/openmldb_cluster`.
563+
* You can specify the username and password to connect to the server using `--user` and `--password`.
564+
* By default, it connects to the server using the root user and an empty password. If you've changed the root password, you need to specify the new password using `--password`.
563565

564566
```
565567
--endpoint=172.27.128.33:8080
@@ -636,6 +638,7 @@ cp conf/taskmanager.properties.template conf/taskmanager.properties
636638
* Modify `offline.data.prefix`: Set it to the storage path for offline tables. In Yarn mode, modify it to the corresponding HDFS path.
637639
* Modify `spark.master`: Set it according to the desired mode. Currently supports local and yarn modes for running offline tasks.
638640
* Modify `spark.home`: Set it to the Spark environment path. If not configured, the `SPARK_HOME` environment variable will be used. It should be the directory where the spark-optimized package was extracted in the first step, and it must be an absolute path.
641+
* You can specify the username and password to connect to the server using `user` and `password`. If you've changed the root password, you'll need to specify the new password for the root user.
639642

640643
```
641644
server.host=172.27.128.33

docs/en/quickstart/cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Below we will describe some commonly used configuration options.
3434

3535
- zk_session_timeout: The expected ZooKeeper session timeout is not necessarily the actual session timeout. If the value is set too large, ZooKeeper Server's tickTime or maxSessionTimeout also needs to be adjusted.
3636

37+
- user: Specify the username for login. If not specified, it defaults to 'root'.
38+
39+
- password: Specify the password for login. If not specified, you'll be prompted to enter the password in interactive mode.
40+
3741
## Non-Interactive Usage
3842

3943
The interface that appears after starting the CLI is called an interactive interface. You need to enter SQL statements and press Enter to execute operations. Here are some non-interactive usage methods for batch processing or debugging.

docs/en/quickstart/sdk/java_sdk.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Connection connection = DriverManager.getConnection("jdbc:openmldb:///?zk=localh
5353

5454
// Set database in jdbcUrl
5555
Connection connection1 = DriverManager.getConnection("jdbc:openmldb:///test_db?zk=localhost:6181&zkPath=/openmldb");
56+
57+
// Set user and password in jdbcUrl
58+
Connection connection = DriverManager.getConnection("jdbc:openmldb:///?zk=localhost:6181&zkPath=/openmldb&user=root&password=123456");
5659
```
5760

5861
The database specified in the Connection address must exist when creating the connection.
@@ -113,6 +116,10 @@ option.setZkCluster("127.0.0.1:2181");
113116
option.setZkPath("/openmldb");
114117
option.setSessionTimeout(10000);
115118
option.setRequestTimeout(60000);
119+
// If not specified, it defaults to 'root'
120+
option.setUser("root");
121+
// If not specified, it defaults to being empty
122+
option.setPassword("123456");
116123
```
117124
Then, use SdkOption to create the Executor.
118125

docs/en/quickstart/sdk/python_sdk.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Parameter `db_name` name must exist, and the database must be created before the
2121
```python
2222
import openmldb.dbapi
2323
db = openmldb.dbapi.connect(zk="$zkcluster", zkPath="$zkpath")
24+
# You can set the username and password as follows. If no username is set, it defaults to 'root', and the password defaults to being empty
25+
# db = openmldb.dbapi.connect(zk="$zkcluster", zkPath="$zkpath", user="$user", password="$password")
2426
cursor = db.cursor()
2527
```
2628

@@ -124,6 +126,8 @@ Parameter `db_name` must exist, and the database must be created before the conn
124126
```python
125127
import sqlalchemy as db
126128
engine = db.create_engine('openmldb:///?zk=127.0.0.1:2181&zkPath=/openmldb')
129+
# You can set the username and password as follows.
130+
# create_engine('openmldb:///db_name?zk=zkcluster&zkPath=zkpath&user=root&password=123456')
127131
connection = engine.connect()
128132
```
129133

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ALTER USER
2+
3+
The `ALTER USER` statement is used to modify a user's password.
4+
5+
## Syntax
6+
```sql
7+
AlterUserstmt ::=
8+
'ALTER' 'USER' [IF EXISTS] UserName SET OptOptionsList
9+
10+
UserName ::= Identifier
11+
12+
OptOptionsList ::=
13+
"OPTIONS" OptionList
14+
15+
OptionList ::=
16+
OptionsListPrefix ")"
17+
18+
OptionsListPrefix ::=
19+
"(" OptionEntry
20+
| OptionsListPrefix "," OptionEntry
21+
22+
OptionEntry ::=
23+
Identifier "=" Identifier
24+
```
25+
26+
## **Examples**
27+
```sql
28+
ALTER USER user1;
29+
-- SUCCEED
30+
ALTER USER IF EXISTS user2 SET OPTIONS(password='123456');
31+
-- SUCCEED
32+
ALTER USER user3 SET OPTIONS (password='123456');
33+
-- SUCCEED
34+
```
35+
36+
```{note}
37+
1. If the password is not specified in the OPTIONS, the password will not be changed
38+
2. You can only specify the password in the OPTIONS
39+
```
40+
41+
## Related SQL
42+
43+
[CREATE USER](./CREATE_USER_STATEMENT.md)
44+
[DROP USER](./DROP_USER_STATEMENT.md)
45+
[SHOW CURRENT_USER](./SHOW_CURRENT_USER_STATEMENT.md)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# CREATE USER
2+
3+
The `CREATE USER` statement is used to create a user
4+
5+
## Syntax
6+
```sql
7+
CreateUserstmt ::=
8+
'CREATE' 'USER' [IF NOT EXISTS] UserName OptOptionsList
9+
10+
UserName ::= Identifier
11+
12+
OptOptionsList ::=
13+
"OPTIONS" OptionList
14+
15+
OptionList ::=
16+
OptionsListPrefix ")"
17+
18+
OptionsListPrefix ::=
19+
"(" OptionEntry
20+
| OptionsListPrefix "," OptionEntry
21+
22+
OptionEntry ::=
23+
Identifier "=" Identifier
24+
```
25+
26+
## **Examples**
27+
```sql
28+
CREATE USER user1;
29+
-- SUCCEED
30+
CREATE USER IF NOT EXISTS user2;
31+
-- SUCCEED
32+
CREATE USER user3 OPTIONS (password='123456');
33+
-- SUCCEED
34+
```
35+
36+
```{note}
37+
1. Only the password can be specified in the OPTIONS
38+
2. The password will be empty if not specified explicitly
39+
```
40+
41+
## Related SQL
42+
43+
[DROP USER](./DROP_USER_STATEMENT.md)
44+
[ALTER USER](./ALTER_USER_STATEMENT.md)
45+
[SHOW CURRENT_USER](./SHOW_CURRENT_USER_STATEMENT.md)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# DROP USER
2+
3+
The `DROP USER` statement is used to drop a user.
4+
5+
## Syntax
6+
```sql
7+
DropUserstmt ::=
8+
'DROP' 'USER' [IF EXISTS] UserName
9+
10+
UserName ::= Identifier
11+
```
12+
13+
## **Examples**
14+
```sql
15+
DROP USER user1;
16+
-- SUCCEED
17+
DROP USER IF EXISTS user2;
18+
-- SUCCEED
19+
```
20+
21+
```{note}
22+
1. The user `root` cannot be deleted
23+
```
24+
25+
## Related SQL
26+
27+
[CREATE USER](./CREATE_USER_STATEMENT.md)
28+
[ALTER USER](./ALTER_USER_STATEMENT.md)
29+
[SHOW CURRENT_USER](./SHOW_CURRENT_USER_STATEMENT.md)

0 commit comments

Comments
 (0)