@@ -24,6 +24,7 @@ use crate::highlighter::{NoSyntaxHighlighter, SyntaxHighlighter};
2424
2525use datafusion:: sql:: parser:: { DFParser , Statement } ;
2626use datafusion:: sql:: sqlparser:: dialect:: dialect_from_str;
27+ use datafusion_common:: config:: Dialect ;
2728
2829use rustyline:: completion:: { Completer , FilenameCompleter , Pair } ;
2930use rustyline:: error:: ReadlineError ;
@@ -34,33 +35,33 @@ use rustyline::{Context, Helper, Result};
3435
3536pub struct CliHelper {
3637 completer : FilenameCompleter ,
37- dialect : String ,
38+ dialect : Dialect ,
3839 highlighter : Box < dyn Highlighter > ,
3940}
4041
4142impl CliHelper {
42- pub fn new ( dialect : & str , color : bool ) -> Self {
43+ pub fn new ( dialect : & Dialect , color : bool ) -> Self {
4344 let highlighter: Box < dyn Highlighter > = if !color {
4445 Box :: new ( NoSyntaxHighlighter { } )
4546 } else {
4647 Box :: new ( SyntaxHighlighter :: new ( dialect) )
4748 } ;
4849 Self {
4950 completer : FilenameCompleter :: new ( ) ,
50- dialect : dialect. into ( ) ,
51+ dialect : * dialect,
5152 highlighter,
5253 }
5354 }
5455
55- pub fn set_dialect ( & mut self , dialect : & str ) {
56- if dialect != self . dialect {
57- self . dialect = dialect. to_string ( ) ;
56+ pub fn set_dialect ( & mut self , dialect : & Dialect ) {
57+ if * dialect != self . dialect {
58+ self . dialect = * dialect;
5859 }
5960 }
6061
6162 fn validate_input ( & self , input : & str ) -> Result < ValidationResult > {
6263 if let Some ( sql) = input. strip_suffix ( ';' ) {
63- let dialect = match dialect_from_str ( & self . dialect ) {
64+ let dialect = match dialect_from_str ( self . dialect ) {
6465 Some ( dialect) => dialect,
6566 None => {
6667 return Ok ( ValidationResult :: Invalid ( Some ( format ! (
@@ -97,7 +98,7 @@ impl CliHelper {
9798
9899impl Default for CliHelper {
99100 fn default ( ) -> Self {
100- Self :: new ( "generic" , false )
101+ Self :: new ( & Dialect :: Generic , false )
101102 }
102103}
103104
@@ -289,7 +290,7 @@ mod tests {
289290 ) ;
290291
291292 // valid in postgresql dialect
292- validator. set_dialect ( "postgresql" ) ;
293+ validator. set_dialect ( & Dialect :: PostgreSQL ) ;
293294 let result =
294295 readline_direct ( Cursor :: new ( r"select 1 # 2;" . as_bytes ( ) ) , & validator) ?;
295296 assert ! ( matches!( result, ValidationResult :: Valid ( None ) ) ) ;
0 commit comments