Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clickhouse for sqlparser #35

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2813,27 +2813,27 @@
//////////////////////////////////
// CREATE PEER statement, for PeerDB.
CreatePeer {
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2816 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2816 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
if_not_exists: bool,
peer_name: ObjectName,
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2819 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2819 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
peer_type: PeerType,
with_options: Vec<SqlOption>,
},
/// DROP PEER [IF EXISTS] peer_name
DropPeer {
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2825 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2825 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
if_exists: bool,
peer_name: ObjectName,
},
CreateMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2830 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2830 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
if_not_exists: bool,
create_mirror: CreateMirror,
},
// DROP MIRROR [IF EXISTS] mirror_name
DropMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2836 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2836 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
if_exists: bool,
mirror_name: ObjectName,
},
Expand All @@ -2842,20 +2842,20 @@
mirror_name: Ident,
},
ResyncMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2845 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2845 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
if_exists: bool,
mirror_name: ObjectName,
with_options: Vec<SqlOption>,
},
// DROP MIRROR [IF EXISTS] mirror_name
PauseMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2852 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2852 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
if_exists: bool,
mirror_name: ObjectName,
},
// RESUME MIRROR [IF EXISTS] mirror_name
ResumeMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]

Check warning on line 2858 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`

Check warning on line 2858 in src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

unexpected `cfg` condition value: `derive-visitor`
if_exists: bool,
mirror_name: ObjectName,
},
Expand All @@ -2876,6 +2876,7 @@
Eventhubs,
PubSub,
Elasticsearch,
Clickhouse,
}

impl fmt::Display for PeerType {
Expand All @@ -2892,6 +2893,7 @@
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,
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",
"PUBSUB",
"ELASTICSEARCH",
"CLICKHOUSE",
];
let err = format!(
"expected peertype as one of {}, got {:#?}",
Expand Down
27 changes: 27 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3678,6 +3678,33 @@ 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);
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
Loading