Skip to content

Commit

Permalink
add new ident parse func: grant_ident
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Feb 14, 2025
1 parent 81b8d88 commit c7da95e
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/query/ast/src/parser/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub fn ident(i: Input) -> IResult<Identifier> {
non_reserved_identifier(|token| token.is_reserved_ident(false))(i)
}

pub fn grant_ident(i: Input) -> IResult<Identifier> {
non_reserved_identifier(|token| token.is_grant_reserved_ident(false, true))(i)
}

pub fn plain_ident(i: Input) -> IResult<Identifier> {
plain_identifier(|token| token.is_reserved_ident(false))(i)
}
Expand Down
13 changes: 13 additions & 0 deletions src/query/ast/src/parser/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ use crate::parser::input::Input;
use crate::parser::token::*;
use crate::parser::ErrorKind;

pub fn parameter_to_grant_string(i: Input) -> IResult<String> {
let ident_to_string = |i| map_res(grant_ident, |ident| Ok(ident.name))(i);
let u64_to_string = |i| map(literal_u64, |v| v.to_string())(i);
let boolean_to_string = |i| map(literal_bool, |v| v.to_string())(i);

rule!(
#literal_string
| #ident_to_string
| #u64_to_string
| #boolean_to_string
)(i)
}

pub fn parameter_to_string(i: Input) -> IResult<String> {
let ident_to_string = |i| map_res(ident, |ident| Ok(ident.name))(i);
let u64_to_string = |i| map(literal_u64, |v| v.to_string())(i);
Expand Down
6 changes: 3 additions & 3 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3435,15 +3435,15 @@ pub fn grant_ownership_level(i: Input) -> IResult<AccountMgrLevel> {
// "*": as current db or "table" with current db
let db = map(
rule! {
( #ident ~ "." )? ~ "*"
( #grant_ident ~ "." )? ~ "*"
},
|(database, _)| AccountMgrLevel::Database(database.map(|(database, _)| database.name)),
);

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

// Object object_name
let object = map(
rule! { #object ~ #ident},
rule! { #object ~ #grant_ident },
|(object, object_name)| match object {
Object::Stage => AccountMgrLevel::Stage(object_name.to_string()),
Object::Udf => AccountMgrLevel::UDF(object_name.to_string()),
Expand Down
8 changes: 7 additions & 1 deletion src/query/ast/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,6 @@ impl TokenKind {
// | TokenKind::RETURNING
| TokenKind::STAGE
| TokenKind::UDF
| TokenKind::WAREHOUSE
| TokenKind::SHARE
| TokenKind::SHARES
| TokenKind::TO
Expand All @@ -1772,6 +1771,13 @@ impl TokenKind {
_ => false
}
}

pub(crate) fn is_grant_reserved_ident(&self, after_as: bool, in_grant: bool) -> bool {
match self {
TokenKind::WAREHOUSE if in_grant => true,
_ => self.is_reserved_ident(after_as),
}
}
}

pub fn all_reserved_keywords() -> Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/tests/it/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn test_statement() {
r#"drop table a;"#,
r#"drop table if exists a."b";"#,
r#"use "a";"#,
r#"create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary');"#,
r#"create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary' warehouse='default');"#,
r#"select current_catalog();"#,
r#"use catalog ctl;"#,
r#"create database if not exists a;"#,
Expand Down
5 changes: 3 additions & 2 deletions src/query/ast/tests/it/testdata/stmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2937,9 +2937,9 @@ UseDatabase {


---------- Input ----------
create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary');
create catalog ctl type=hive connection=(url='<hive-meta-store>' thrift_protocol='binary' warehouse='default');
---------- Output ---------
CREATE CATALOG ctl TYPE=HIVE CONNECTION = ( thrift_protocol = 'binary', url = '<hive-meta-store>' )
CREATE CATALOG ctl TYPE=HIVE CONNECTION = ( thrift_protocol = 'binary', url = '<hive-meta-store>', warehouse = 'default' )
---------- AST ------------
CreateCatalog(
CreateCatalogStmt {
Expand All @@ -2949,6 +2949,7 @@ CreateCatalog(
catalog_options: {
"thrift_protocol": "binary",
"url": "<hive-meta-store>",
"warehouse": "default",
},
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SHOW CATALOGS;
default

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

statement ok
DROP CATALOG IF EXISTS ctl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@ select SPLIT(definition, '\n') from system.tasks where name = 'transactionTask'
----
['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;']




statement ok
DROP TASK transactionTask
2 changes: 1 addition & 1 deletion tests/sqllogictests/suites/tpch_iceberg/prune.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TYPE=ICEBERG
CONNECTION=(
TYPE='rest'
ADDRESS='http://127.0.0.1:8181'
`WAREHOUSE`='s3://iceberg-tpch'
WAREHOUSE='s3://iceberg-tpch'
"s3.region"='us-east-1'
"s3.endpoint"='http://127.0.0.1:9000'
);
Expand Down
2 changes: 1 addition & 1 deletion tests/sqllogictests/suites/tpch_iceberg/queries.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TYPE=ICEBERG
CONNECTION=(
TYPE='rest'
ADDRESS='http://127.0.0.1:8181'
`WAREHOUSE`='s3://iceberg-tpch'
WAREHOUSE='s3://iceberg-tpch'
"s3.region"='us-east-1'
"s3.endpoint"='http://127.0.0.1:9000'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TYPE=ICEBERG
CONNECTION=(
TYPE='rest'
ADDRESS='http://127.0.0.1:8181'
`WAREHOUSE`='s3://icebergdata/demo'
WAREHOUSE='s3://icebergdata/demo'
);
EOF

Expand Down

0 comments on commit c7da95e

Please sign in to comment.