mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-27 16:09:09 +00:00
Add support for string literal concatenation (#2003)
Some checks failed
license / Release Audit Tool (RAT) (push) Has been cancelled
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / compile (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
Some checks failed
license / Release Audit Tool (RAT) (push) Has been cancelled
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / compile (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
eca65742ba
commit
cff28334be
4 changed files with 39 additions and 2 deletions
|
@ -476,6 +476,12 @@ pub trait Dialect: Debug + Any {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the dialect supports concatenating of string literal
|
||||||
|
/// Example: `SELECT 'Hello ' "world" => SELECT 'Hello world'`
|
||||||
|
fn supports_string_literal_concatenation(&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#function_concat>
|
||||||
|
fn supports_string_literal_concatenation(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn ignores_wildcard_escapes(&self) -> bool {
|
fn ignores_wildcard_escapes(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -9914,8 +9914,12 @@ 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) => ok_value(Value::SingleQuotedString(
|
||||||
Token::DoubleQuotedString(ref s) => ok_value(Value::DoubleQuotedString(s.to_string())),
|
self.maybe_concat_string_literal(s.to_string()),
|
||||||
|
)),
|
||||||
|
Token::DoubleQuotedString(ref s) => ok_value(Value::DoubleQuotedString(
|
||||||
|
self.maybe_concat_string_literal(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()))
|
||||||
}
|
}
|
||||||
|
@ -9985,6 +9989,18 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn maybe_concat_string_literal(&mut self, mut str: String) -> String {
|
||||||
|
if self.dialect.supports_string_literal_concatenation() {
|
||||||
|
while let Token::SingleQuotedString(ref s) | Token::DoubleQuotedString(ref s) =
|
||||||
|
self.peek_token_ref().token
|
||||||
|
{
|
||||||
|
str.push_str(s.clone().as_str());
|
||||||
|
self.advance_token();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str
|
||||||
|
}
|
||||||
|
|
||||||
/// 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()?;
|
||||||
|
|
|
@ -17150,3 +17150,13 @@ fn test_parse_semantic_view_table_factor() {
|
||||||
_ => panic!("Expected Query statement"),
|
_ => panic!("Expected Query statement"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_adjacent_string_literal_concatenation() {
|
||||||
|
let sql = r#"SELECT 'M' "y" 'S' "q" 'l'"#;
|
||||||
|
let dialects = all_dialects_where(|d| d.supports_string_literal_concatenation());
|
||||||
|
dialects.one_statement_parses_to(sql, r"SELECT 'MySql'");
|
||||||
|
|
||||||
|
let sql = "SELECT * FROM t WHERE col = 'Hello' \n ' ' \t 'World!'";
|
||||||
|
dialects.one_statement_parses_to(sql, r"SELECT * FROM t WHERE col = 'Hello World!'");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue