Skip to content

Commit

Permalink
add new ident parse func: option_ident
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Feb 14, 2025
1 parent 81b8d88 commit b13e777
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 8 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 option_ident(i: Input) -> IResult<Identifier> {
non_reserved_identifier(|token| token.is_option_reserved_ident(false, true))(i)
}

pub fn plain_ident(i: Input) -> IResult<Identifier> {
plain_identifier(|token| token.is_reserved_ident(false))(i)
}
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn connection_opt(sep: &'static str) -> impl FnMut(Input) -> IResult<(String
move |i| {
let string_options = map(
rule! {
#ident ~ #match_text(sep) ~ #literal_string
#option_ident ~ #match_text(sep) ~ #literal_string
},
|(k, _, v)| (k.to_string().to_lowercase(), v),
);
Expand Down
7 changes: 7 additions & 0 deletions src/query/ast/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,13 @@ impl TokenKind {
_ => false
}
}

pub(crate) fn is_option_reserved_ident(&self, after_as: bool, in_option: bool) -> bool {
match self {
TokenKind::WAREHOUSE if in_option => false,
_ => 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
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 b13e777

Please sign in to comment.