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

Commit ea9e81c

Browse files
authored
Merge pull request #24 from umanwizard/schema_optional
make schema optional
2 parents 2eedfb2 + 31ee653 commit ea9e81c

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/ast/mod.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ pub enum Statement {
529529
CreateSource {
530530
name: ObjectName,
531531
url: String,
532-
schema: SourceSchema,
532+
schema: Option<SourceSchema>,
533533
with_options: Vec<SqlOption>,
534534
},
535535
/// `CREATE SOURCES`
@@ -736,17 +736,23 @@ impl fmt::Display for Statement {
736736
} => {
737737
write!(
738738
f,
739-
"CREATE SOURCE {} FROM {} USING SCHEMA ",
739+
"CREATE SOURCE {} FROM {}",
740740
name.to_string(),
741741
Value::SingleQuotedString(url.clone()).to_string()
742742
)?;
743743
match schema {
744-
SourceSchema::Raw(schema) => {
745-
write!(f, "{}", Value::SingleQuotedString(schema.clone()))?;
746-
}
747-
SourceSchema::Registry(url) => {
748-
write!(f, "REGISTRY {}", Value::SingleQuotedString(url.clone()))?;
744+
Some(schema) => {
745+
write!(f, " USING SCHEMA ")?;
746+
match schema {
747+
SourceSchema::Raw(schema) => {
748+
write!(f, "{}", Value::SingleQuotedString(schema.clone()))?;
749+
}
750+
SourceSchema::Registry(url) => {
751+
write!(f, "REGISTRY {}", Value::SingleQuotedString(url.clone()))?;
752+
}
753+
}
749754
}
755+
None => {}
750756
}
751757
if !with_options.is_empty() {
752758
write!(f, " WITH ({})", display_comma_separated(with_options))?;

src/ast/visit_macro.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ macro_rules! make_visitor {
343343
&mut self,
344344
name: &'ast $($mut)* ObjectName,
345345
url: &'ast $($mut)* String,
346-
schema: &'ast $($mut)* SourceSchema,
346+
schema: Option<&'ast $($mut)* SourceSchema>,
347347
with_options: &'ast $($mut)* Vec<SqlOption>,
348348
) {
349349
visit_create_source(self, name, url, schema, with_options)
@@ -612,7 +612,7 @@ macro_rules! make_visitor {
612612
url,
613613
schema,
614614
with_options,
615-
} => visitor.visit_create_source(name, url, schema, with_options),
615+
} => visitor.visit_create_source(name, url, schema.as_auto_ref(), with_options),
616616
Statement::CreateSources {
617617
like,
618618
url,
@@ -1255,12 +1255,14 @@ macro_rules! make_visitor {
12551255
visitor: &mut V,
12561256
name: &'ast $($mut)* ObjectName,
12571257
url: &'ast $($mut)* String,
1258-
schema: &'ast $($mut)* SourceSchema,
1258+
schema: Option<&'ast $($mut)* SourceSchema>,
12591259
with_options: &'ast $($mut)* Vec<SqlOption>,
12601260
) {
12611261
visitor.visit_object_name(name);
12621262
visitor.visit_literal_string(url);
1263-
visitor.visit_source_schema(schema);
1263+
if let Some(schema) = schema {
1264+
visitor.visit_source_schema(schema);
1265+
}
12641266
for option in with_options {
12651267
visitor.visit_option(option);
12661268
}

src/parser.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1145,12 +1145,15 @@ impl Parser {
11451145
let name = self.parse_object_name()?;
11461146
self.expect_keyword("FROM")?;
11471147
let url = self.parse_literal_string()?;
1148-
self.expect_keyword("USING")?;
1149-
self.expect_keyword("SCHEMA")?;
1150-
let schema = if self.parse_keyword("REGISTRY") {
1151-
SourceSchema::Registry(self.parse_literal_string()?)
1148+
let schema = if self.parse_keywords(vec!["USING", "SCHEMA"]) {
1149+
let schema = if self.parse_keyword("REGISTRY") {
1150+
SourceSchema::Registry(self.parse_literal_string()?)
1151+
} else {
1152+
SourceSchema::Raw(self.parse_literal_string()?)
1153+
};
1154+
Some(schema)
11521155
} else {
1153-
SourceSchema::Raw(self.parse_literal_string()?)
1156+
None
11541157
};
11551158
let with_options = self.parse_with_options()?;
11561159
Ok(Statement::CreateSource {

0 commit comments

Comments
 (0)