mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-25 16:34:04 +00:00
Merge 04c8f9bb1d
into 6e80e5c237
This commit is contained in:
commit
14df49f7e7
4 changed files with 61 additions and 2 deletions
|
@ -476,6 +476,12 @@ pub trait Dialect: Debug + Any {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Does the Dialect support concatenating of string literal
|
||||||
|
// Example: SELECT 'Hello ' "world" => SELECT 'Hello world'
|
||||||
|
fn supports_concat_quoted_identifiers(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
/// Does the dialect support trailing commas in the projection list?
|
/// Does the dialect support trailing commas in the projection list?
|
||||||
fn supports_projection_trailing_commas(&self) -> bool {
|
fn supports_projection_trailing_commas(&self) -> bool {
|
||||||
self.supports_trailing_commas()
|
self.supports_trailing_commas()
|
||||||
|
|
|
@ -71,6 +71,11 @@ impl Dialect for MySqlDialect {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see <https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#:~:text=mysql%3E%20SELECT%20%27My%27%20%27S%27%20%27QL%27%3B%0A%20%20%20%20%20%20%20%20%2D%3E%20%27MySQL%27>
|
||||||
|
fn supports_concat_quoted_identifiers(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn ignores_wildcard_escapes(&self) -> bool {
|
fn ignores_wildcard_escapes(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -9765,8 +9765,18 @@ impl<'a> Parser<'a> {
|
||||||
// bigdecimal feature is enabled, and is otherwise a no-op
|
// bigdecimal feature is enabled, and is otherwise a no-op
|
||||||
// (i.e., it returns the input string).
|
// (i.e., it returns the input string).
|
||||||
Token::Number(n, l) => ok_value(Value::Number(Self::parse(n, span.start)?, l)),
|
Token::Number(n, l) => ok_value(Value::Number(Self::parse(n, span.start)?, l)),
|
||||||
Token::SingleQuotedString(ref s) => ok_value(Value::SingleQuotedString(s.to_string())),
|
Token::SingleQuotedString(ref s) => {
|
||||||
Token::DoubleQuotedString(ref s) => ok_value(Value::DoubleQuotedString(s.to_string())),
|
if self.dialect.supports_concat_quoted_identifiers() {
|
||||||
|
return ok_value(Value::SingleQuotedString(self.combine_quoted(next_token)));
|
||||||
|
}
|
||||||
|
ok_value(Value::SingleQuotedString(s.to_string()))
|
||||||
|
}
|
||||||
|
Token::DoubleQuotedString(ref s) => {
|
||||||
|
if self.dialect.supports_concat_quoted_identifiers() {
|
||||||
|
return ok_value(Value::DoubleQuotedString(self.combine_quoted(next_token)));
|
||||||
|
}
|
||||||
|
ok_value(Value::DoubleQuotedString(s.to_string()))
|
||||||
|
}
|
||||||
Token::TripleSingleQuotedString(ref s) => {
|
Token::TripleSingleQuotedString(ref s) => {
|
||||||
ok_value(Value::TripleSingleQuotedString(s.to_string()))
|
ok_value(Value::TripleSingleQuotedString(s.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -9836,6 +9846,35 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_quoted_string(&self, token: &Token) -> bool {
|
||||||
|
matches!(
|
||||||
|
token,
|
||||||
|
Token::SingleQuotedString(_) | Token::DoubleQuotedString(_)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_quoted_string(&self, token: &Token) -> String {
|
||||||
|
match token {
|
||||||
|
Token::SingleQuotedString(s) => s.clone(),
|
||||||
|
Token::DoubleQuotedString(s) => s.clone(),
|
||||||
|
_ => String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn combine_quoted(&mut self, token: TokenWithSpan) -> String {
|
||||||
|
let mut combined_string = self.get_quoted_string(&token.token);
|
||||||
|
loop {
|
||||||
|
let next_token = self.next_token();
|
||||||
|
if !self.is_quoted_string(&next_token.token) {
|
||||||
|
self.prev_token();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let s = self.get_quoted_string(&next_token.token);
|
||||||
|
combined_string.push_str(&s);
|
||||||
|
}
|
||||||
|
combined_string
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse an unsigned numeric literal
|
/// Parse an unsigned numeric literal
|
||||||
pub fn parse_number_value(&mut self) -> Result<ValueWithSpan, ParserError> {
|
pub fn parse_number_value(&mut self) -> Result<ValueWithSpan, ParserError> {
|
||||||
let value_wrapper = self.parse_value()?;
|
let value_wrapper = self.parse_value()?;
|
||||||
|
|
|
@ -4247,3 +4247,12 @@ fn test_create_index_options() {
|
||||||
"CREATE INDEX idx_name ON t(c1, c2) USING BTREE LOCK = EXCLUSIVE ALGORITHM = DEFAULT",
|
"CREATE INDEX idx_name ON t(c1, c2) USING BTREE LOCK = EXCLUSIVE ALGORITHM = DEFAULT",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_adjacent_string_literal_concatenation() {
|
||||||
|
let sql = r#"SELECT 'M' "y" 'S' "q" 'l'"#;
|
||||||
|
mysql().one_statement_parses_to(sql, r"SELECT 'MySql'");
|
||||||
|
|
||||||
|
let sql = "SELECT * FROM t WHERE col = 'Hello' \n ' ' \t 'World!'";
|
||||||
|
mysql().one_statement_parses_to(sql, r"SELECT * FROM t WHERE col = 'Hello World!'");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue