Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ where
Self: Into<T>,
{
#[inline(always)]
#[cfg_attr(feature = "recursive-protection", recursive::recursive)]
fn convert(value: Self) -> T {
Self::into(value)
}
Expand Down Expand Up @@ -4575,9 +4576,17 @@ impl fmt::Display for Statement {
"{hivevar}{name} = {l_paren}{value}{r_paren}",
hivevar = if *hivevar { "HIVEVAR:" } else { "" },
name = variables,
l_paren = if parenthesized { "(" } else { Default::default() },
l_paren = if parenthesized {
"("
} else {
Default::default()
},
value = display_comma_separated(value),
r_paren = if parenthesized { ")" } else { Default::default() },
r_paren = if parenthesized {
")"
} else {
Default::default()
},
)
}
Statement::SetTimeZone { local, value } => {
Expand Down
3 changes: 1 addition & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2364,8 +2364,7 @@ impl<'a> Parser<'a> {
self.expect_token(&Token::LParen)?;
let mut trim_where = None;
if let Token::Word(word) = self.peek_token().token {
if [Keyword::BOTH, Keyword::LEADING, Keyword::TRAILING].contains(&word.keyword)
{
if [Keyword::BOTH, Keyword::LEADING, Keyword::TRAILING].contains(&word.keyword) {
trim_where = Some(self.parse_trim_where()?);
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13348,3 +13348,16 @@ fn parse_range_range_align_to_calculate() {
"Expected: end of statement, found: )",
);
}

#[test]
fn convert_to_datafusion_statement_overflow() {
let expr = std::iter::repeat_n("num BETWEEN 0 AND 1", 1000)
.collect::<Vec<_>>()
.join(" OR ");
let sql = format!("SELECT num FROM numbers WHERE {expr}");

let mut statements = Parser::parse_sql(&GenericDialect {}, sql.as_str()).unwrap();
let statement = statements.pop().unwrap();
let df_statement: df_sqlparser::ast::Statement = statement.into();
assert_eq!(df_statement.to_string(), sql);
}
4 changes: 3 additions & 1 deletion tests/sqlparser_duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,9 @@ fn parse_use() {
for &quote in &quote_styles {
// Test double identifier with different type of quotes
assert_eq!(
duckdb().verified_stmt(&format!("USE {quote}CATALOG{quote}.{quote}my_schema{quote}")),
duckdb().verified_stmt(&format!(
"USE {quote}CATALOG{quote}.{quote}my_schema{quote}"
)),
Statement::Use(Use::Object(ObjectName(vec![
Ident::with_quote(quote, "CATALOG"),
Ident::with_quote(quote, "my_schema")
Expand Down
3 changes: 1 addition & 2 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,7 @@ fn parse_use() {
for &quote in &quote_styles {
// Test single identifier with different type of quotes
assert_eq!(
mysql_and_generic()
.verified_stmt(&format!("USE {quote}{object_name}{quote}")),
mysql_and_generic().verified_stmt(&format!("USE {quote}{object_name}{quote}")),
Statement::Use(Use::Object(ObjectName(vec![Ident::with_quote(
quote,
object_name.to_string(),
Expand Down
12 changes: 7 additions & 5 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2234,9 +2234,7 @@ fn test_snowflake_stage_object_names() {
.zip(allowed_object_names.iter_mut())
{
let (formatted_name, object_name) = it;
let sql = format!(
"COPY INTO {formatted_name} FROM 'gcs://mybucket/./../a.csv'"
);
let sql = format!("COPY INTO {formatted_name} FROM 'gcs://mybucket/./../a.csv'");
match snowflake().verified_stmt(&sql) {
Statement::CopyIntoSnowflake { into, .. } => {
assert_eq!(into.0, object_name.0)
Expand Down Expand Up @@ -2714,7 +2712,9 @@ fn parse_use() {
for &quote in &quote_styles {
// Test double identifier with different type of quotes
assert_eq!(
snowflake().verified_stmt(&format!("USE {quote}CATALOG{quote}.{quote}my_schema{quote}")),
snowflake().verified_stmt(&format!(
"USE {quote}CATALOG{quote}.{quote}my_schema{quote}"
)),
Statement::Use(Use::Object(ObjectName(vec![
Ident::with_quote(quote, "CATALOG"),
Ident::with_quote(quote, "my_schema")
Expand Down Expand Up @@ -2747,7 +2747,9 @@ fn parse_use() {
)])))
);
assert_eq!(
snowflake().verified_stmt(&format!("USE SCHEMA {quote}CATALOG{quote}.{quote}my_schema{quote}")),
snowflake().verified_stmt(&format!(
"USE SCHEMA {quote}CATALOG{quote}.{quote}my_schema{quote}"
)),
Statement::Use(Use::Schema(ObjectName(vec![
Ident::with_quote(quote, "CATALOG"),
Ident::with_quote(quote, "my_schema")
Expand Down
Loading