Skip to content

Commit

Permalink
support clickhouse for sqlparser
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed May 6, 2024
1 parent d76527b commit 9ea67ca
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,7 @@ pub enum PeerType {
Eventhubs,
PubSub,
Elasticsearch,
Clickhouse,
}

impl fmt::Display for PeerType {
Expand All @@ -2892,6 +2893,7 @@ impl fmt::Display for PeerType {
PeerType::Eventhubs => write!(f, "EVENTHUBS"),
PeerType::PubSub => write!(f, "PUBSUB"),
PeerType::Elasticsearch => write!(f, "ELASTICSEARCH"),
PeerType::Clickhouse => write!(f, "CLICKHOUSE"),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ define_keywords!(
CHARSET,
CHAR_LENGTH,
CHECK,
CLICKHOUSE,
CLOB,
CLONE,
CLOSE,
Expand Down
3 changes: 3 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9828,6 +9828,7 @@ impl<'a> Parser<'a> {
Keyword::EVENTHUBS,

Check failure on line 9828 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/src/parser/mod.rs

Check failure on line 9828 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/src/parser/mod.rs
Keyword::PUBSUB,
Keyword::ELASTICSEARCH,
Keyword::CLICKHOUSE
]) {
Some(Keyword::BIGQUERY) => Ok(PeerType::Bigquery),
Some(Keyword::MONGO) => Ok(PeerType::Mongo),
Expand All @@ -9840,6 +9841,7 @@ impl<'a> Parser<'a> {
Some(Keyword::EVENTHUBS) => Ok(PeerType::Eventhubs),
Some(Keyword::PUBSUB) => Ok(PeerType::PubSub),
Some(Keyword::ELASTICSEARCH) => Ok(PeerType::Elasticsearch),
Some(Keyword::CLICKHOUSE) => Ok(PeerType::Clickhouse),
other => {
let supported_peer_types = [
"BIGQUERY",
Expand All @@ -9853,6 +9855,7 @@ impl<'a> Parser<'a> {
"EVENTHUBS",

Check failure on line 9855 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/src/parser/mod.rs

Check failure on line 9855 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/src/parser/mod.rs
"PUBSUB",
"ELASTICSEARCH",
"CLICKHOUSE"
];
let err = format!(
"expected peertype as one of {}, got {:#?}",
Expand Down
29 changes: 29 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3678,6 +3678,35 @@ fn parse_create_s3_peer() {
}
}

#[test]
fn parse_create_clickhouse_peer() {
match pg().verified_stmt(
"CREATE PEER clickhouse_1 FROM CLICKHOUSE WITH \
(host = 'http://clickhouse-server:8123')",
) {
Statement::CreatePeer {
if_not_exists: _,
peer_name: _,
peer_type,
with_options,
} => {
assert_eq!(peer_type, PeerType::Clickhouse);

Check failure on line 3693 in tests/sqlparser_postgres.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/tests/sqlparser_postgres.rs

Check failure on line 3693 in tests/sqlparser_postgres.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/tests/sqlparser_postgres.rs
assert_eq!(
with_options,
vec![
SqlOption {
name: Ident::new("host"),
value: Expr::Value(Value::SingleQuotedString(String::from(
"http://clickhouse-server:8123"
)))
},
]
);
}
_ => unreachable!(),
}
}

#[test]
fn parse_create_single_mirror() {
match pg().verified_stmt("CREATE MIRROR IF NOT EXISTS test_mirror FROM p1 TO p2 WITH TABLE MAPPING ({from : s1.t1, to : s2.t2}) WITH (key1 = 'value1')") {
Expand Down

0 comments on commit 9ea67ca

Please sign in to comment.