@@ -36,11 +36,12 @@ enum ValType {
3636
3737// Describes Kafka cluster configurations users can suppply using `CREATE
3838// SOURCE...WITH (option_list)`.
39- // TODO(sploiselle): Support overriding keys, default values .
39+ // TODO(sploiselle): Support overriding keys.
4040struct Config {
4141 name : & ' static str ,
4242 val_type : ValType ,
4343 transform : fn ( String ) -> String ,
44+ default : Option < String > ,
4445}
4546
4647impl Config {
@@ -49,6 +50,7 @@ impl Config {
4950 name,
5051 val_type,
5152 transform : convert:: identity,
53+ default : None ,
5254 }
5355 }
5456
@@ -69,6 +71,12 @@ impl Config {
6971 self
7072 }
7173
74+ // Allows for returning a default value for this configuration option
75+ fn set_default ( mut self , d : Option < String > ) -> Self {
76+ self . default = d;
77+ self
78+ }
79+
7280 // Get the appropriate String to use as the Kafka config key.
7381 fn get_key ( & self ) -> String {
7482 self . name . replace ( "_" , "." )
@@ -105,7 +113,12 @@ fn extract(
105113 Ok ( v) => v,
106114 Err ( e) => bail ! ( "Invalid WITH option {}={}: {}" , config. name, v, e) ,
107115 } ,
108- None => continue ,
116+ None => match & config. default {
117+ Some ( v) => v. to_string ( ) ,
118+ None => {
119+ continue ;
120+ }
121+ } ,
109122 } ;
110123 out. insert ( config. get_key ( ) , value) ;
111124 }
@@ -134,7 +147,10 @@ pub fn extract_config(
134147 // The range of values comes from `statistics.interval.ms` in
135148 // https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
136149 ValType :: Number ( 0 , 86_400_000 ) ,
137- ) ,
150+ )
151+ . set_default ( Some (
152+ chrono:: Duration :: seconds ( 1 ) . num_milliseconds ( ) . to_string ( ) ,
153+ ) ) ,
138154 Config :: new (
139155 "topic_metadata_refresh_interval_ms" ,
140156 // The range of values comes from `topic.metadata.refresh.interval.ms` in
0 commit comments