Skip to content

Commit 09b199c

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat-multi-catalog
2 parents e9894e5 + 1c3fcf2 commit 09b199c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+523
-456
lines changed

common/ast/src/parser/ast/expression.rs renamed to common/ast/src/ast/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use std::fmt::Formatter;
1717

1818
use sqlparser::ast::Value;
1919

20-
use super::Identifier;
21-
use super::Query;
22-
use crate::parser::ast::display_identifier_vec;
20+
use crate::ast::display_identifier_vec;
21+
use crate::ast::Identifier;
22+
use crate::ast::Query;
2323

2424
#[derive(Debug, Clone, PartialEq)]
2525
#[allow(dead_code)]

common/ast/src/parser/ast/mod.rs renamed to common/ast/src/ast/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
mod ast_visitor;
16-
mod expression;
15+
mod expr;
1716
mod query;
1817
mod statement;
1918

2019
use std::fmt::Display;
2120
use std::fmt::Formatter;
2221

23-
pub use expression::*;
22+
pub use expr::*;
2423
pub use query::*;
2524
pub use statement::*;
2625

common/ast/src/parser/ast/query.rs renamed to common/ast/src/ast/query.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use std::fmt::Display;
1616
use std::fmt::Formatter;
1717

18-
use crate::parser::ast::display_identifier_vec;
19-
use crate::parser::ast::Expr;
20-
use crate::parser::ast::Identifier;
18+
use crate::ast::display_identifier_vec;
19+
use crate::ast::Expr;
20+
use crate::ast::Identifier;
2121

2222
// Root node of a query tree
2323
#[derive(Debug, Clone, PartialEq)]

common/ast/src/parser/ast/statement.rs renamed to common/ast/src/ast/statement.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use std::fmt::Display;
1616
use std::fmt::Formatter;
1717

18-
use super::expression::Literal;
19-
use super::expression::TypeName;
20-
use super::Identifier;
21-
use crate::parser::ast::display_identifier_vec;
22-
use crate::parser::ast::query::Query;
18+
use crate::ast::display_identifier_vec;
19+
use crate::ast::expr::Literal;
20+
use crate::ast::expr::TypeName;
21+
use crate::ast::Identifier;
22+
use crate::ast::Query;
2323

2424
// SQL statement
2525
#[derive(Debug, Clone, PartialEq)]

common/ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
pub mod ast;
1516
pub mod parser;
1617
pub mod udfs;

common/ast/src/parser/rule/error.rs renamed to common/ast/src/parser/error.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use std::ops::Range;
1616

17-
use crate::parser::rule::util::Input;
1817
use crate::parser::token::TokenKind;
18+
use crate::parser::util::Input;
1919

2020
/// This error type accumulates errors and their position when backtracking
2121
/// through a parse tree. This take a deepest error at `alt` combinator.
@@ -121,3 +121,41 @@ impl<'a> Error<'a> {
121121
.collect()
122122
}
123123
}
124+
125+
pub fn pretty_print_error(source: &str, lables: Vec<(Range<usize>, String)>) -> String {
126+
use codespan_reporting::diagnostic::Diagnostic;
127+
use codespan_reporting::diagnostic::Label;
128+
use codespan_reporting::files::SimpleFile;
129+
use codespan_reporting::term;
130+
use codespan_reporting::term::termcolor::Buffer;
131+
use codespan_reporting::term::Chars;
132+
use codespan_reporting::term::Config;
133+
134+
let mut writer = Buffer::no_color();
135+
let file = SimpleFile::new("SQL", source);
136+
let config = Config {
137+
chars: Chars::ascii(),
138+
before_label_lines: 3,
139+
..Default::default()
140+
};
141+
142+
let lables = lables
143+
.into_iter()
144+
.enumerate()
145+
.map(|(i, (span, msg))| {
146+
if i == 0 {
147+
Label::primary((), span).with_message(msg)
148+
} else {
149+
Label::secondary((), span).with_message(msg)
150+
}
151+
})
152+
.collect();
153+
154+
let diagnostic = Diagnostic::error().with_labels(lables);
155+
156+
term::emit(&mut writer, &config, &file, &diagnostic).unwrap();
157+
158+
std::str::from_utf8(&writer.into_inner())
159+
.unwrap()
160+
.to_string()
161+
}

common/ast/src/parser/rule/expr.rs renamed to common/ast/src/parser/expr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ use pratt::PrattError;
2424
use pratt::PrattParser;
2525
use pratt::Precedence;
2626

27-
use crate::parser::ast::*;
28-
use crate::parser::rule::error::Error;
29-
use crate::parser::rule::error::ErrorKind;
30-
use crate::parser::rule::statement::*;
31-
use crate::parser::rule::util::*;
27+
use crate::ast::*;
28+
use crate::parser::error::Error;
29+
use crate::parser::error::ErrorKind;
30+
use crate::parser::query::*;
3231
use crate::parser::token::*;
32+
use crate::parser::util::*;
3333
use crate::rule;
3434

3535
const BETWEEN_PREC: u32 = 20;

common/ast/src/parser/expr/mod.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

common/ast/src/parser/mod.rs

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,30 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
pub mod ast;
15+
pub mod error;
1616
pub mod expr;
17-
pub mod rule;
17+
pub mod query;
18+
pub mod statement;
1819
pub mod token;
19-
20-
use std::ops::Range;
20+
pub mod util;
2121

2222
use common_exception::ErrorCode;
2323
use common_exception::Result;
2424
use nom::combinator::map;
2525

26-
use self::rule::statement::statement;
27-
use self::token::TokenKind;
28-
use self::token::Tokenizer;
29-
use crate::parser::ast::Statement;
26+
use crate::ast::Statement;
27+
use crate::parser::error::pretty_print_error;
28+
use crate::parser::statement::statement;
29+
use crate::parser::token::TokenKind;
30+
use crate::parser::token::Tokenizer;
3031
use crate::rule;
3132

3233
/// Parse a SQL string into `Statement`s.
3334
pub fn parse_sql(sql: &str) -> Result<Vec<Statement>> {
3435
let tokens = Tokenizer::new(sql).collect::<Result<Vec<_>>>()?;
3536
let stmt = map(rule! { #statement ~ ";" }, |(stmt, _)| stmt);
3637
let mut stmts = rule! { #stmt+ };
38+
3739
match stmts(tokens.as_slice()) {
3840
Ok((rest, stmts)) if rest[0].kind == TokenKind::EOI => Ok(stmts),
3941
Ok((rest, _)) => Err(ErrorCode::SyntaxException(pretty_print_error(sql, vec![(
@@ -46,41 +48,3 @@ pub fn parse_sql(sql: &str) -> Result<Vec<Statement>> {
4648
Err(nom::Err::Incomplete(_)) => unreachable!(),
4749
}
4850
}
49-
50-
pub fn pretty_print_error(source: &str, lables: Vec<(Range<usize>, String)>) -> String {
51-
use codespan_reporting::diagnostic::Diagnostic;
52-
use codespan_reporting::diagnostic::Label;
53-
use codespan_reporting::files::SimpleFile;
54-
use codespan_reporting::term;
55-
use codespan_reporting::term::termcolor::Buffer;
56-
use codespan_reporting::term::Chars;
57-
use codespan_reporting::term::Config;
58-
59-
let mut writer = Buffer::no_color();
60-
let file = SimpleFile::new("SQL", source);
61-
let config = Config {
62-
chars: Chars::ascii(),
63-
before_label_lines: 3,
64-
..Default::default()
65-
};
66-
67-
let lables = lables
68-
.into_iter()
69-
.enumerate()
70-
.map(|(i, (span, msg))| {
71-
if i == 0 {
72-
Label::primary((), span).with_message(msg)
73-
} else {
74-
Label::secondary((), span).with_message(msg)
75-
}
76-
})
77-
.collect();
78-
79-
let diagnostic = Diagnostic::error().with_labels(lables);
80-
81-
term::emit(&mut writer, &config, &file, &diagnostic).unwrap();
82-
83-
std::str::from_utf8(&writer.into_inner())
84-
.unwrap()
85-
.to_string()
86-
}

0 commit comments

Comments
 (0)