Skip to content

Commit c7da95e

Browse files
committed
add new ident parse func: grant_ident
1 parent 81b8d88 commit c7da95e

File tree

11 files changed

+35
-14
lines changed

11 files changed

+35
-14
lines changed

src/query/ast/src/parser/common.rs

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ pub fn ident(i: Input) -> IResult<Identifier> {
8888
non_reserved_identifier(|token| token.is_reserved_ident(false))(i)
8989
}
9090

91+
pub fn grant_ident(i: Input) -> IResult<Identifier> {
92+
non_reserved_identifier(|token| token.is_grant_reserved_ident(false, true))(i)
93+
}
94+
9195
pub fn plain_ident(i: Input) -> IResult<Identifier> {
9296
plain_identifier(|token| token.is_reserved_ident(false))(i)
9397
}

src/query/ast/src/parser/stage.rs

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ use crate::parser::input::Input;
3030
use crate::parser::token::*;
3131
use crate::parser::ErrorKind;
3232

33+
pub fn parameter_to_grant_string(i: Input) -> IResult<String> {
34+
let ident_to_string = |i| map_res(grant_ident, |ident| Ok(ident.name))(i);
35+
let u64_to_string = |i| map(literal_u64, |v| v.to_string())(i);
36+
let boolean_to_string = |i| map(literal_bool, |v| v.to_string())(i);
37+
38+
rule!(
39+
#literal_string
40+
| #ident_to_string
41+
| #u64_to_string
42+
| #boolean_to_string
43+
)(i)
44+
}
45+
3346
pub fn parameter_to_string(i: Input) -> IResult<String> {
3447
let ident_to_string = |i| map_res(ident, |ident| Ok(ident.name))(i);
3548
let u64_to_string = |i| map(literal_u64, |v| v.to_string())(i);

src/query/ast/src/parser/statement.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3435,15 +3435,15 @@ pub fn grant_ownership_level(i: Input) -> IResult<AccountMgrLevel> {
34353435
// "*": as current db or "table" with current db
34363436
let db = map(
34373437
rule! {
3438-
( #ident ~ "." )? ~ "*"
3438+
( #grant_ident ~ "." )? ~ "*"
34393439
},
34403440
|(database, _)| AccountMgrLevel::Database(database.map(|(database, _)| database.name)),
34413441
);
34423442

34433443
// `db01`.'tb1' or `db01`.`tb1` or `db01`.tb1
34443444
let table = map(
34453445
rule! {
3446-
( #ident ~ "." )? ~ #parameter_to_string
3446+
( #grant_ident ~ "." )? ~ #parameter_to_grant_string
34473447
},
34483448
|(database, table)| {
34493449
AccountMgrLevel::Table(database.map(|(database, _)| database.name), table)
@@ -3464,7 +3464,7 @@ pub fn grant_ownership_level(i: Input) -> IResult<AccountMgrLevel> {
34643464

34653465
// Object object_name
34663466
let object = map(
3467-
rule! { #object ~ #ident},
3467+
rule! { #object ~ #grant_ident },
34683468
|(object, object_name)| match object {
34693469
Object::Stage => AccountMgrLevel::Stage(object_name.to_string()),
34703470
Object::Udf => AccountMgrLevel::UDF(object_name.to_string()),

src/query/ast/src/parser/token.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,6 @@ impl TokenKind {
17531753
// | TokenKind::RETURNING
17541754
| TokenKind::STAGE
17551755
| TokenKind::UDF
1756-
| TokenKind::WAREHOUSE
17571756
| TokenKind::SHARE
17581757
| TokenKind::SHARES
17591758
| TokenKind::TO
@@ -1772,6 +1771,13 @@ impl TokenKind {
17721771
_ => false
17731772
}
17741773
}
1774+
1775+
pub(crate) fn is_grant_reserved_ident(&self, after_as: bool, in_grant: bool) -> bool {
1776+
match self {
1777+
TokenKind::WAREHOUSE if in_grant => true,
1778+
_ => self.is_reserved_ident(after_as),
1779+
}
1780+
}
17751781
}
17761782

17771783
pub fn all_reserved_keywords() -> Vec<String> {

src/query/ast/tests/it/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn test_statement() {
137137
r#"drop table a;"#,
138138
r#"drop table if exists a."b";"#,
139139
r#"use "a";"#,
140-
r#"create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary');"#,
140+
r#"create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary' warehouse='default');"#,
141141
r#"select current_catalog();"#,
142142
r#"use catalog ctl;"#,
143143
r#"create database if not exists a;"#,

src/query/ast/tests/it/testdata/stmt.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -2937,9 +2937,9 @@ UseDatabase {
29372937

29382938

29392939
---------- Input ----------
2940-
create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary');
2940+
create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary' warehouse='default');
29412941
---------- Output ---------
2942-
CREATE CATALOG ctl TYPE=HIVE CONNECTION = ( thrift_protocol = 'binary', url = '<hive-meta-store>' )
2942+
CREATE CATALOG ctl TYPE=HIVE CONNECTION = ( thrift_protocol = 'binary', url = '<hive-meta-store>', warehouse = 'default' )
29432943
---------- AST ------------
29442944
CreateCatalog(
29452945
CreateCatalogStmt {
@@ -2949,6 +2949,7 @@ CreateCatalog(
29492949
catalog_options: {
29502950
"thrift_protocol": "binary",
29512951
"url": "<hive-meta-store>",
2952+
"warehouse": "default",
29522953
},
29532954
},
29542955
)

tests/sqllogictests/suites/base/05_ddl/05_0029_ddl_create_catalog.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SHOW CATALOGS;
1010
default
1111

1212
statement error 1001
13-
CREATE CATALOG ctl TYPE=ICEBERG CONNECTION=(TYPE='REST' ADDRESS='http://127.0.0.1:1000' `WAREHOUSE`='default' );
13+
CREATE CATALOG ctl TYPE=ICEBERG CONNECTION=(TYPE='REST' ADDRESS='http://127.0.0.1:1000' WAREHOUSE='default' );
1414

1515
statement ok
1616
DROP CATALOG IF EXISTS ctl;

tests/sqllogictests/suites/task/task_ddl_transaction_test.test

-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,5 @@ select SPLIT(definition, '\n') from system.tasks where name = 'transactionTask'
6161
----
6262
['BEGIN','SELECT 2024;','BEGIN;','MERGE INTO t USING s ON t.id = s.id WHEN MATCHED THEN UPDATE *;','DELETE FROM t WHERE c = '';'';','ABORT;','END;']
6363

64-
65-
66-
6764
statement ok
6865
DROP TASK transactionTask

tests/sqllogictests/suites/tpch_iceberg/prune.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TYPE=ICEBERG
77
CONNECTION=(
88
TYPE='rest'
99
ADDRESS='http://127.0.0.1:8181'
10-
`WAREHOUSE`='s3://iceberg-tpch'
10+
WAREHOUSE='s3://iceberg-tpch'
1111
"s3.region"='us-east-1'
1212
"s3.endpoint"='http://127.0.0.1:9000'
1313
);

tests/sqllogictests/suites/tpch_iceberg/queries.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TYPE=ICEBERG
77
CONNECTION=(
88
TYPE='rest'
99
ADDRESS='http://127.0.0.1:8181'
10-
`WAREHOUSE`='s3://iceberg-tpch'
10+
WAREHOUSE='s3://iceberg-tpch'
1111
"s3.region"='us-east-1'
1212
"s3.endpoint"='http://127.0.0.1:9000'
1313
);

tests/suites/3_stateful_iceberg/00_rest/00_0000_create_and_show.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TYPE=ICEBERG
1212
CONNECTION=(
1313
TYPE='rest'
1414
ADDRESS='http://127.0.0.1:8181'
15-
`WAREHOUSE`='s3://icebergdata/demo'
15+
WAREHOUSE='s3://icebergdata/demo'
1616
);
1717
EOF
1818

0 commit comments

Comments
 (0)