@@ -22,11 +22,8 @@ use std::borrow::Cow;
22
22
23
23
use crate :: highlighter:: { NoSyntaxHighlighter , SyntaxHighlighter } ;
24
24
25
- use datafusion:: common:: sql_datafusion_err;
26
- use datafusion:: error:: DataFusionError ;
27
25
use datafusion:: sql:: parser:: { DFParser , Statement } ;
28
26
use datafusion:: sql:: sqlparser:: dialect:: dialect_from_str;
29
- use datafusion:: sql:: sqlparser:: parser:: ParserError ;
30
27
31
28
use rustyline:: completion:: { Completer , FilenameCompleter , Pair } ;
32
29
use rustyline:: error:: ReadlineError ;
@@ -63,15 +60,6 @@ impl CliHelper {
63
60
64
61
fn validate_input ( & self , input : & str ) -> Result < ValidationResult > {
65
62
if let Some ( sql) = input. strip_suffix ( ';' ) {
66
- let sql = match unescape_input ( sql) {
67
- Ok ( sql) => sql,
68
- Err ( err) => {
69
- return Ok ( ValidationResult :: Invalid ( Some ( format ! (
70
- " 🤔 Invalid statement: {err}" ,
71
- ) ) ) )
72
- }
73
- } ;
74
-
75
63
let dialect = match dialect_from_str ( & self . dialect ) {
76
64
Some ( dialect) => dialect,
77
65
None => {
@@ -166,40 +154,8 @@ impl Validator for CliHelper {
166
154
167
155
impl Helper for CliHelper { }
168
156
169
- /// Unescape input string from readline.
170
- ///
171
- /// The data read from stdio will be escaped, so we need to unescape the input before executing the input
172
- pub fn unescape_input ( input : & str ) -> datafusion:: error:: Result < String > {
173
- let mut chars = input. chars ( ) ;
174
-
175
- let mut result = String :: with_capacity ( input. len ( ) ) ;
176
- while let Some ( char) = chars. next ( ) {
177
- if char == '\\' {
178
- if let Some ( next_char) = chars. next ( ) {
179
- // https://static.rust-lang.org/doc/master/reference.html#literals
180
- result. push ( match next_char {
181
- '0' => '\0' ,
182
- 'n' => '\n' ,
183
- 'r' => '\r' ,
184
- 't' => '\t' ,
185
- '\\' => '\\' ,
186
- _ => {
187
- return Err ( sql_datafusion_err ! ( ParserError :: TokenizerError (
188
- format!( "unsupported escape char: '\\ {}'" , next_char)
189
- ) ) )
190
- }
191
- } ) ;
192
- }
193
- } else {
194
- result. push ( char) ;
195
- }
196
- }
197
-
198
- Ok ( result)
199
- }
200
-
201
157
/// Splits a string which consists of multiple queries.
202
- pub ( crate ) fn split_from_semicolon ( sql : String ) -> Vec < String > {
158
+ pub ( crate ) fn split_from_semicolon ( sql : & str ) -> Vec < String > {
203
159
let mut commands = Vec :: new ( ) ;
204
160
let mut current_command = String :: new ( ) ;
205
161
let mut in_single_quote = false ;
@@ -310,14 +266,13 @@ mod tests {
310
266
) ?;
311
267
assert ! ( matches!( result, ValidationResult :: Valid ( None ) ) ) ;
312
268
313
- // should be invalid
314
269
let result = readline_direct (
315
- Cursor :: new (
316
- r"create external table test stored as csv location 'data.csv' options ('format.delimiter' '\u{07}');"
317
- . as_bytes ( ) ) ,
318
- & validator,
319
- ) ?;
320
- assert ! ( matches!( result, ValidationResult :: Invalid ( Some ( _ ) ) ) ) ;
270
+ Cursor :: new (
271
+ r"select '\', '\\', '\\\\\', 'dsdsds\\\\', '\t', '\0', '\n';" . as_bytes ( ) ,
272
+ ) ,
273
+ & validator,
274
+ ) ?;
275
+ assert ! ( matches!( result, ValidationResult :: Valid ( None ) ) ) ;
321
276
322
277
Ok ( ( ) )
323
278
}
@@ -346,34 +301,34 @@ mod tests {
346
301
fn test_split_from_semicolon ( ) {
347
302
let sql = "SELECT 1; SELECT 2;" ;
348
303
let expected = vec ! [ "SELECT 1;" , "SELECT 2;" ] ;
349
- assert_eq ! ( split_from_semicolon( sql. to_string ( ) ) , expected) ;
304
+ assert_eq ! ( split_from_semicolon( sql) , expected) ;
350
305
351
306
let sql = r#"SELECT ";";"# ;
352
307
let expected = vec ! [ r#"SELECT ";";"# ] ;
353
- assert_eq ! ( split_from_semicolon( sql. to_string ( ) ) , expected) ;
308
+ assert_eq ! ( split_from_semicolon( sql) , expected) ;
354
309
355
310
let sql = "SELECT ';';" ;
356
311
let expected = vec ! [ "SELECT ';';" ] ;
357
- assert_eq ! ( split_from_semicolon( sql. to_string ( ) ) , expected) ;
312
+ assert_eq ! ( split_from_semicolon( sql) , expected) ;
358
313
359
314
let sql = r#"SELECT 1; SELECT 'value;value'; SELECT 1 as "text;text";"# ;
360
315
let expected = vec ! [
361
316
"SELECT 1;" ,
362
317
"SELECT 'value;value';" ,
363
318
r#"SELECT 1 as "text;text";"# ,
364
319
] ;
365
- assert_eq ! ( split_from_semicolon( sql. to_string ( ) ) , expected) ;
320
+ assert_eq ! ( split_from_semicolon( sql) , expected) ;
366
321
367
322
let sql = "" ;
368
323
let expected: Vec < String > = Vec :: new ( ) ;
369
- assert_eq ! ( split_from_semicolon( sql. to_string ( ) ) , expected) ;
324
+ assert_eq ! ( split_from_semicolon( sql) , expected) ;
370
325
371
326
let sql = "SELECT 1" ;
372
327
let expected = vec ! [ "SELECT 1;" ] ;
373
- assert_eq ! ( split_from_semicolon( sql. to_string ( ) ) , expected) ;
328
+ assert_eq ! ( split_from_semicolon( sql) , expected) ;
374
329
375
330
let sql = "SELECT 1; " ;
376
331
let expected = vec ! [ "SELECT 1;" ] ;
377
- assert_eq ! ( split_from_semicolon( sql. to_string ( ) ) , expected) ;
332
+ assert_eq ! ( split_from_semicolon( sql) , expected) ;
378
333
}
379
334
}
0 commit comments