Skip to content

Commit 7fb486c

Browse files
authored
fix: display query parse error (#632)
* fix: display query parse error root@localhost:8000/default/default> explain select * from default.t1 where a in ('x'); Parser 'explain select * from default.t1 where a in ('x');' failed with error 'unable to recognize the rest tokens' * add test
1 parent b5afd78 commit 7fb486c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

cli/src/session.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ impl Session {
483483
self.query.push('\n');
484484
}
485485
self.query.push_str(line);
486+
let mut err = String::new();
486487

487488
'Parser: loop {
488489
let mut is_valid = true;
@@ -510,16 +511,20 @@ impl Session {
510511
}
511512
previous_token_backslash = matches!(token.kind, TokenKind::Backslash);
512513
}
513-
Err(_) => {
514+
Err(e) => {
514515
// ignore current query if have invalid token.
515516
is_valid = false;
517+
err = e.to_string();
516518
continue;
517519
}
518520
}
519521
}
520522
break;
521523
}
522524

525+
if self.query.is_empty() && queries.is_empty() && !err.is_empty() {
526+
eprintln!("Parser '{}' failed\nwith error '{}'", line, err);
527+
}
523528
queries
524529
}
525530

cli/tests/00-base.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ a"
1818
-9999999999999999999999999999999999999999999999999999999999999999999999999999
1919
1
2020
NULL
21+
Parser 'CREATE TABLE 🐳🍞(🐳🐳 INTEGER, 🍞🍞 INTEGER);' failed
22+
with error 'unable to recognize the rest tokens'
23+
Parser 'explain select * from c where b in ('x');' failed
24+
with error 'unable to recognize the rest tokens'
2125
3.00 3.00 0.0000000170141183460469231731687303715884105727000 -0.0000000170141183460469231731687303715884105727000
2226
Asia/Shanghai
2327
3

cli/tests/00-base.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ drop table t;
3232
-- issue 572
3333
CREATE TABLE 🐳🍞(🐳🐳 INTEGER, 🍞🍞 INTEGER);
3434

35+
-- issue 631
36+
explain select * from c where b in'x');
37+
3538
-- enable it after we support code string in databend
3639
-- select $$aa$$;
3740
-- select $$

0 commit comments

Comments
 (0)