From bea5b984d846ac10212e10610f567713d90f79f3 Mon Sep 17 00:00:00 2001 From: Joey Hain Date: Thu, 22 Jan 2026 12:21:52 -0800 Subject: [PATCH 1/2] support backslash escapes in string literals on databricks --- src/dialect/databricks.rs | 5 +++++ tests/sqlparser_databricks.rs | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/dialect/databricks.rs b/src/dialect/databricks.rs index 74e3798918..3ad525011a 100644 --- a/src/dialect/databricks.rs +++ b/src/dialect/databricks.rs @@ -84,4 +84,9 @@ impl Dialect for DatabricksDialect { fn supports_nested_comments(&self) -> bool { true } + + // https://docs.databricks.com/aws/en/sql/language-manual/data-types/string-type#literals + fn supports_string_literal_backslash_escape(&self) -> bool { + true + } } diff --git a/tests/sqlparser_databricks.rs b/tests/sqlparser_databricks.rs index b9d6b28a3a..9a0043f442 100644 --- a/tests/sqlparser_databricks.rs +++ b/tests/sqlparser_databricks.rs @@ -18,7 +18,7 @@ use sqlparser::ast::helpers::attached_token::AttachedToken; use sqlparser::ast::*; use sqlparser::dialect::{DatabricksDialect, GenericDialect}; -use sqlparser::parser::ParserError; +use sqlparser::parser::{ParserError, ParserOptions}; use test_utils::*; #[macro_use] @@ -28,6 +28,13 @@ fn databricks() -> TestedDialects { TestedDialects::new(vec![Box::new(DatabricksDialect {})]) } +fn databricks_no_unescape() -> TestedDialects { + TestedDialects::new_with_options( + vec![Box::new(DatabricksDialect {})], + ParserOptions::new().with_unescape(false), + ) +} + fn databricks_and_generic() -> TestedDialects { TestedDialects::new(vec![ Box::new(DatabricksDialect {}), @@ -54,6 +61,22 @@ fn test_databricks_identifiers() { ); } +// Test examples from https://docs.databricks.com/aws/en/sql/language-manual/data-types/string-type#examples +// +// Note: string literals are broken on DBx when unescape in turned on (the default). +#[test] +fn test_databricks_string_literals() { + databricks_no_unescape().verified_expr(r"'O\'Connell'"); + databricks_no_unescape().verified_expr(r"'Some\nText'"); + databricks_no_unescape().verified_expr("'μ„œμšΈμ‹œ'"); + databricks_no_unescape().verified_expr(r"'\\'"); + + // FIXME: raw strings are broken + // databricks_no_unescape().verified_query(r"SELECT 'Hou$e', 'Hou\$e', r'Hou$e', r'Hou\$e'"); + // databricks_no_unescape().verified_expr(r"r'Some\nText'"); + // databricks_no_unescape().verified_expr(r"r'\\'"); +} + #[test] fn test_databricks_exists() { // exists is a function in databricks From 28af4c9597a3ba74f0e4c3d8b94540f2d7a10978 Mon Sep 17 00:00:00 2001 From: Joey Hain Date: Thu, 22 Jan 2026 12:26:48 -0800 Subject: [PATCH 2/2] suppress new clippy lint --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index dbfd1791a7..c2fe50794d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,6 +153,8 @@ // Splitting complex nodes (expressions, statements, types) into separate types // would bloat the API and hide intent. Extra memory is a worthwhile tradeoff. #![allow(clippy::large_enum_variant)] +// TODO: Fix and remove this. +#![expect(clippy::unnecessary_unwrap)] // Allow proc-macros to find this crate extern crate self as sqlparser;