Skip to content
This repository was archived by the owner on Dec 25, 2019. It is now read-only.

Commit a9818a4

Browse files
committed
Extend sqlparser semantics to support protobuf schemas
The format = protobuf_descriptor and message_name = "message_name" arguments can be WITH args
1 parent ed5574c commit a9818a4

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

src/ast/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl fmt::Display for Statement {
745745
Some(schema) => {
746746
write!(f, " USING SCHEMA ")?;
747747
match schema {
748-
SourceSchema::Raw(schema) => {
748+
SourceSchema::RawOrPath(schema) => {
749749
write!(f, "{}", Value::SingleQuotedString(schema.clone()))?;
750750
}
751751
SourceSchema::Registry(url) => {
@@ -1031,8 +1031,9 @@ impl fmt::Display for Function {
10311031
/// Specifies the schema associated with a given Kafka topic.
10321032
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10331033
pub enum SourceSchema {
1034-
/// The schema is specified directly in the contained string.
1035-
Raw(String),
1034+
/// The schema is specified directly in the contained string
1035+
/// or its a path to a file
1036+
RawOrPath(String),
10361037
/// The schema is available in a Confluent-compatible schema registry that
10371038
/// is accessible at the specified URL.
10381039
Registry(String),

src/ast/visit_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ macro_rules! make_visitor {
12921292
source_schema: &'ast $($mut)* SourceSchema,
12931293
) {
12941294
match source_schema {
1295-
SourceSchema::Raw(schema) => visitor.visit_literal_string(schema),
1295+
SourceSchema::RawOrPath(schema) => visitor.visit_literal_string(schema),
12961296
SourceSchema::Registry(url) => visitor.visit_literal_string(url),
12971297
}
12981298
}

src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ impl Parser {
12381238
let schema = if self.parse_keyword("REGISTRY") {
12391239
SourceSchema::Registry(self.parse_literal_string()?)
12401240
} else {
1241-
SourceSchema::Raw(self.parse_literal_string()?)
1241+
SourceSchema::RawOrPath(self.parse_literal_string()?)
12421242
};
12431243
Some(schema)
12441244
} else {

tests/sqlparser_common.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -2878,7 +2878,7 @@ fn parse_create_source_raw_schema() {
28782878
} => {
28792879
assert_eq!("foo", name.to_string());
28802880
assert_eq!("bar", url);
2881-
assert_eq!(SourceSchema::Raw("baz".into()), schema.unwrap());
2881+
assert_eq!(SourceSchema::RawOrPath("baz".into()), schema.unwrap());
28822882
assert_eq!(
28832883
with_options,
28842884
vec![SqlOption {
@@ -2891,6 +2891,37 @@ fn parse_create_source_raw_schema() {
28912891
}
28922892
}
28932893

2894+
#[test]
2895+
fn parse_create_source_path_schema_multiple_args() {
2896+
let sql = "CREATE SOURCE foo FROM 'bar' USING SCHEMA 'path' WITH (format = 'someformat', message_name = 'somemessage')";
2897+
match verified_stmt(sql) {
2898+
Statement::CreateSource {
2899+
name,
2900+
url,
2901+
schema,
2902+
with_options,
2903+
} => {
2904+
assert_eq!("foo", name.to_string());
2905+
assert_eq!("bar", url);
2906+
assert_eq!(SourceSchema::RawOrPath("path".into()), schema.unwrap());
2907+
assert_eq!(
2908+
with_options,
2909+
vec![
2910+
SqlOption {
2911+
name: "format".into(),
2912+
value: Value::SingleQuotedString("someformat".into())
2913+
},
2914+
SqlOption {
2915+
name: "message_name".into(),
2916+
value: Value::SingleQuotedString("somemessage".into())
2917+
},
2918+
]
2919+
);
2920+
}
2921+
_ => assert!(false),
2922+
}
2923+
}
2924+
28942925
#[test]
28952926
fn parse_create_source_registry() {
28962927
let sql = "CREATE SOURCE foo FROM 'bar' USING SCHEMA REGISTRY 'http://localhost:8081'";

0 commit comments

Comments
 (0)