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
5 changes: 5 additions & 0 deletions src/dialect/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 24 additions & 1 deletion tests/sqlparser_databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 {}),
Expand All @@ -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
Expand Down