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

Refactor eventhubs peer #30

Merged
merged 6 commits into from
Apr 1, 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
6 changes: 2 additions & 4 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2372,11 +2372,10 @@ pub enum PeerType {
Mongo,
Snowflake,
Postgres,
EventHub,
EventHubGroup,
S3,
SQLServer,
Kafka,
Eventhubs,
}

impl fmt::Display for PeerType {
Expand All @@ -2386,11 +2385,10 @@ impl fmt::Display for PeerType {
PeerType::Mongo => write!(f, "MONGO"),
PeerType::Snowflake => write!(f, "SNOWFLAKE"),
PeerType::Postgres => write!(f, "POSTGRES"),
PeerType::EventHub => write!(f, "EVENTHUB"),
PeerType::EventHubGroup => write!(f, "EVENTHUBGROUP"),
PeerType::S3 => write!(f, "S3"),
PeerType::SQLServer => write!(f, "SQLSERVER"),
PeerType::Kafka => write!(f, "KAFKA"),
PeerType::Eventhubs => write!(f, "EVENTHUBS"),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ define_keywords!(
ERROR,
ESCAPE,
EVENT,
EVENTHUB,
EVENTHUBGROUP,
EVENTHUBS,
EVERY,
EXCEPT,
EXCLUDE,
Expand Down
9 changes: 3 additions & 6 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use crate::ast::helpers::stmt_create_table::CreateTableBuilder;
use crate::ast::*;
use crate::dialect::*;
use crate::keywords::{self, Keyword, ALL_KEYWORDS};

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `keywords` is imported redundantly

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `keywords` is imported redundantly

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `keywords` is imported redundantly

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `keywords` is imported redundantly

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `keywords` is imported redundantly

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `keywords` is imported redundantly

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `keywords` is imported redundantly

Check warning on line 33 in src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `keywords` is imported redundantly
use crate::tokenizer::*;

mod alter;
Expand Down Expand Up @@ -8396,18 +8396,16 @@
Keyword::KAFKA,
Keyword::S3,
Keyword::SQLSERVER,
Keyword::EVENTHUB,
Keyword::EVENTHUBGROUP,
Keyword::EVENTHUBS,
]) {
Some(Keyword::BIGQUERY) => Ok(PeerType::Bigquery),
Some(Keyword::MONGO) => Ok(PeerType::Mongo),
Some(Keyword::SNOWFLAKE) => Ok(PeerType::Snowflake),
Some(Keyword::POSTGRES) => Ok(PeerType::Postgres),
Some(Keyword::KAFKA) => Ok(PeerType::Kafka),
Some(Keyword::S3) => Ok(PeerType::S3),
Some(Keyword::EVENTHUB) => Ok(PeerType::EventHub),
Some(Keyword::SQLSERVER) => Ok(PeerType::SQLServer),
Some(Keyword::EVENTHUBGROUP) => Ok(PeerType::EventHubGroup),
Some(Keyword::EVENTHUBS) => Ok(PeerType::Eventhubs),
other => {
let supported_peer_types = [
"BIGQUERY",
Expand All @@ -8417,8 +8415,7 @@
"KAFKA",
"S3",
"SQLSERVER",
"EVENTHUB",
"EVENTHUBGROUP",
"EVENTHUBS",
];
let err = format!(
"expected peertype as one of {}, got {:#?}",
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
//! is also tested (on the inputs it can handle).

use matches::assert_matches;
use sqlparser::ast::Expr;

Check warning on line 18 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `Expr` is imported redundantly

Check warning on line 18 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `Expr` is imported redundantly

Check warning on line 18 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `Expr` is imported redundantly

Check warning on line 18 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `Expr` is imported redundantly
use sqlparser::ast::Value;

Check warning on line 19 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `Value` is imported redundantly

Check warning on line 19 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `Value` is imported redundantly

Check warning on line 19 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (nightly)

the item `Value` is imported redundantly

Check warning on line 19 in tests/sqlparser_mysql.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the item `Value` is imported redundantly
use sqlparser::ast::*;
use sqlparser::dialect::{GenericDialect, MySqlDialect};
use sqlparser::parser::ParserOptions;
Expand Down Expand Up @@ -202,7 +202,7 @@
fn parse_show_create() {
let obj_name = ObjectName(vec![Ident::new("myident")]);

for obj_type in &vec![
for obj_type in &[
ShowCreateObject::Table,
ShowCreateObject::Trigger,
ShowCreateObject::Event,
Expand Down
51 changes: 44 additions & 7 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3415,22 +3415,59 @@ fn parse_create_single_mirror_no_options() {
}

#[test]
fn parse_create_eventhub_group_peer() {
match pg()
.verified_stmt("CREATE PEER eventhub_group_1 FROM EVENTHUBGROUP WITH (customer_1 = true)")
{
fn parse_create_eventhubs_peer() {
match pg().verified_stmt(
r#"CREATE PEER eventhubs_1 FROM EVENTHUBS WITH (eventhubs = '[
{
"subscription_id":"mysubscriptionid1",
"resource_group":"my-resource-1",
"namespace":"test-namespace-1",
"location":"eastus",
"partition_count":5,
"message_retention_in_days":2
},
{
"subscription_id":"mysubscriptionid2",
"resource_group":"my-resource-2",
"namespace":"test-namespace-2",
"location":"eastus",
"partition_count":5,
"message_retention_in_days":2
}
]')"#,
) {
Statement::CreatePeer {
if_not_exists: _,
peer_name: _,
peer_type,
with_options,
} => {
assert_eq!(peer_type, PeerType::EventHubGroup);
assert_eq!(peer_type, PeerType::Eventhubs);
assert_eq!(
with_options,
vec![SqlOption {
name: Ident::new("customer_1"),
value: sqlparser::ast::Value::Boolean(true)
name: Ident::new("eventhubs"),
value: Value::SingleQuotedString(
r#"[
{
"subscription_id":"mysubscriptionid1",
"resource_group":"my-resource-1",
"namespace":"test-namespace-1",
"location":"eastus",
"partition_count":5,
"message_retention_in_days":2
},
{
"subscription_id":"mysubscriptionid2",
"resource_group":"my-resource-2",
"namespace":"test-namespace-2",
"location":"eastus",
"partition_count":5,
"message_retention_in_days":2
}
]"#
.into(),
)
}]
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ fn test_snowflake_stage_object_names() {
"@namespace.stage_name/path",
"@~/path",
];
let mut allowed_object_names = vec![
let mut allowed_object_names = [
ObjectName(vec![Ident::new("my_company"), Ident::new("emp_basic")]),
ObjectName(vec![Ident::new("@namespace"), Ident::new("%table_name")]),
ObjectName(vec![
Expand Down
Loading