@@ -816,6 +816,15 @@ impl Parser {
816
816
}
817
817
}
818
818
819
+ /// Bail out if the following tokens are not the excpected sequence of keywords,
820
+ /// or consume them if they are
821
+ pub fn expect_keywords ( & mut self , expected : & [ & ' static str ] ) -> Result < ( ) , ParserError > {
822
+ for kw in expected {
823
+ self . expect_keyword ( kw) ?;
824
+ }
825
+ Ok ( ( ) )
826
+ }
827
+
819
828
/// Consume the next token if it matches the expected token, otherwise return false
820
829
#[ must_use]
821
830
pub fn consume_token ( & mut self , expected : & Token ) -> bool {
@@ -846,6 +855,8 @@ impl Parser {
846
855
self . parse_create_view ( )
847
856
} else if self . parse_keyword ( "SOURCE" ) {
848
857
self . parse_create_source ( )
858
+ } else if self . parse_keyword ( "SOURCES" ) {
859
+ self . parse_create_sources ( )
849
860
} else if self . parse_keyword ( "SINK" ) {
850
861
self . parse_create_sink ( )
851
862
} else if self . parse_keyword ( "EXTERNAL" ) {
@@ -869,10 +880,7 @@ impl Parser {
869
880
} else {
870
881
SourceSchema :: Raw ( self . parse_literal_string ( ) ?)
871
882
} ;
872
- let mut with_options = vec ! [ ] ;
873
- if self . parse_keyword ( "WITH" ) {
874
- with_options = self . parse_with_options ( ) ?;
875
- }
883
+ let with_options = self . parse_with_options ( ) ?;
876
884
Ok ( Statement :: CreateSource {
877
885
name,
878
886
url,
@@ -881,16 +889,26 @@ impl Parser {
881
889
} )
882
890
}
883
891
892
+ pub fn parse_create_sources ( & mut self ) -> Result < Statement , ParserError > {
893
+ self . expect_keyword ( "FROM" ) ?;
894
+ let url = self . parse_literal_string ( ) ?;
895
+ self . expect_keywords ( & [ "USING" , "SCHEMA" , "REGISTRY" ] ) ?;
896
+ let schema_registry = self . parse_literal_string ( ) ?;
897
+ let with_options = self . parse_with_options ( ) ?;
898
+ Ok ( Statement :: CreateSources {
899
+ url,
900
+ schema_registry,
901
+ with_options,
902
+ } )
903
+ }
904
+
884
905
pub fn parse_create_sink ( & mut self ) -> Result < Statement , ParserError > {
885
906
let name = self . parse_object_name ( ) ?;
886
907
self . expect_keyword ( "FROM" ) ?;
887
908
let from = self . parse_object_name ( ) ?;
888
909
self . expect_keyword ( "INTO" ) ?;
889
910
let url = self . parse_literal_string ( ) ?;
890
- let mut with_options = vec ! [ ] ;
891
- if self . parse_keyword ( "WITH" ) {
892
- with_options = self . parse_with_options ( ) ?;
893
- }
911
+ let with_options = self . parse_with_options ( ) ?;
894
912
Ok ( Statement :: CreateSink {
895
913
name,
896
914
from,
@@ -928,11 +946,7 @@ impl Parser {
928
946
// ANSI SQL and Postgres support RECURSIVE here, but we don't support it either.
929
947
let name = self . parse_object_name ( ) ?;
930
948
let columns = self . parse_parenthesized_column_list ( Optional ) ?;
931
- let with_options = if self . parse_keyword ( "WITH" ) {
932
- self . parse_with_options ( ) ?
933
- } else {
934
- vec ! [ ]
935
- } ;
949
+ let with_options = self . parse_with_options ( ) ?;
936
950
self . expect_keyword ( "AS" ) ?;
937
951
let query = Box :: new ( self . parse_query ( ) ?) ;
938
952
// Optional `WITH [ CASCADED | LOCAL ] CHECK OPTION` is widely supported here.
@@ -983,11 +997,7 @@ impl Parser {
983
997
// parse optional column list (schema)
984
998
let ( columns, constraints) = self . parse_columns ( ) ?;
985
999
986
- let with_options = if self . parse_keyword ( "WITH" ) {
987
- self . parse_with_options ( ) ?
988
- } else {
989
- vec ! [ ]
990
- } ;
1000
+ let with_options = self . parse_with_options ( ) ?;
991
1001
992
1002
Ok ( Statement :: CreateTable {
993
1003
name : table_name,
@@ -1135,19 +1145,23 @@ impl Parser {
1135
1145
}
1136
1146
1137
1147
pub fn parse_with_options ( & mut self ) -> Result < Vec < SqlOption > , ParserError > {
1138
- self . expect_token ( & Token :: LParen ) ?;
1139
- let mut options = vec ! [ ] ;
1140
- loop {
1141
- let name = self . parse_identifier ( ) ?;
1142
- self . expect_token ( & Token :: Eq ) ?;
1143
- let value = self . parse_value ( ) ?;
1144
- options. push ( SqlOption { name, value } ) ;
1145
- if !self . consume_token ( & Token :: Comma ) {
1146
- break ;
1148
+ if self . parse_keyword ( "WITH" ) {
1149
+ self . expect_token ( & Token :: LParen ) ?;
1150
+ let mut options = vec ! [ ] ;
1151
+ loop {
1152
+ let name = self . parse_identifier ( ) ?;
1153
+ self . expect_token ( & Token :: Eq ) ?;
1154
+ let value = self . parse_value ( ) ?;
1155
+ options. push ( SqlOption { name, value } ) ;
1156
+ if !self . consume_token ( & Token :: Comma ) {
1157
+ break ;
1158
+ }
1147
1159
}
1160
+ self . expect_token ( & Token :: RParen ) ?;
1161
+ Ok ( options)
1162
+ } else {
1163
+ Ok ( vec ! [ ] )
1148
1164
}
1149
- self . expect_token ( & Token :: RParen ) ?;
1150
- Ok ( options)
1151
1165
}
1152
1166
1153
1167
pub fn parse_alter ( & mut self ) -> Result < Statement , ParserError > {
0 commit comments