You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/10/01 19:11:15 UTC
(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2558-8f4da49c082b9cc6a3826e389b5fc5ac0d823efe created (now aa1b5d6de)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-2558-8f4da49c082b9cc6a3826e389b5fc5ac0d823efe
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
at aa1b5d6de SQLite: Support `CAST(expr AS)` without a type name (#2558)
This branch includes the following new commits:
new aa1b5d6de SQLite: Support `CAST(expr AS)` without a type name (#2558)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion-sqlparser-rs) 01/01: SQLite: Support `CAST(expr AS)` without a type name (#2558)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-2558-8f4da49c082b9cc6a3826e389b5fc5ac0d823efe
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit aa1b5d6de30c1047ba6033a6474f6b3c23d16164
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Thu Oct 1 19:10:50 2026 +0000
SQLite: Support `CAST(expr AS)` without a type name (#2558)
---
src/ast/mod.rs | 6 +++++-
src/dialect/mod.rs | 12 ++++++++++++
src/dialect/sqlite.rs | 4 ++++
src/parser/mod.rs | 8 +++++++-
tests/sqlparser_sqlite.rs | 12 ++++++++++++
5 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index d97f23dac..f1035eaee 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -2029,7 +2029,11 @@ impl fmt::Display for Expr {
format,
} => match kind {
CastKind::Cast => {
- write!(f, "CAST({expr} AS {data_type}")?;
+ if matches!(data_type, DataType::Unspecified) {
+ write!(f, "CAST({expr} AS")?;
+ } else {
+ write!(f, "CAST({expr} AS {data_type}")?;
+ }
if let Some(format) = format {
write!(f, " FORMAT {format}")?;
}
diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs
index 6a3d30f1c..47becc038 100644
--- a/src/dialect/mod.rs
+++ b/src/dialect/mod.rs
@@ -1963,6 +1963,18 @@ pub trait Dialect: Debug + Any {
fn supports_map_literal_with_angle_brackets(&self) -> bool {
false
}
+
+ /// Returns true if the dialect supports `CAST(expr AS)` with an empty type name.
+ ///
+ /// Example:
+ /// ```sql
+ /// SELECT CAST(a AS)
+ /// ```
+ ///
+ /// [SQLite](https://www.sqlite.org/lang_expr.html)
+ fn supports_cast_empty_data_type_to_unspecified(&self) -> bool {
+ false
+ }
}
/// Operators for which precedence must be defined.
diff --git a/src/dialect/sqlite.rs b/src/dialect/sqlite.rs
index 418a89e7c..6dec7949b 100644
--- a/src/dialect/sqlite.rs
+++ b/src/dialect/sqlite.rs
@@ -130,6 +130,10 @@ impl Dialect for SQLiteDialect {
true
}
+ fn supports_cast_empty_data_type_to_unspecified(&self) -> bool {
+ true
+ }
+
fn supports_national_string_literal(&self) -> bool {
false
}
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index df6dc358f..99d42de39 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -2925,7 +2925,13 @@ impl<'a> Parser<'a> {
self.expect_token(&Token::LParen)?;
let expr = self.parse_expr()?;
self.expect_keyword_is(Keyword::AS)?;
- let data_type = self.parse_data_type()?;
+ let data_type = if self.dialect.supports_cast_empty_data_type_to_unspecified()
+ && self.peek_token_ref().token == Token::RParen
+ {
+ DataType::Unspecified
+ } else {
+ self.parse_data_type()?
+ };
let format = self.parse_optional_cast_format()?;
self.expect_token(&Token::RParen)?;
Ok(Expr::Cast {
diff --git a/tests/sqlparser_sqlite.rs b/tests/sqlparser_sqlite.rs
index 22043004a..1d478818f 100644
--- a/tests/sqlparser_sqlite.rs
+++ b/tests/sqlparser_sqlite.rs
@@ -957,6 +957,18 @@ fn parse_pattern_operators_bind_at_like_precedence() {
}
}
+#[test]
+fn test_cast_empty_type() {
+ // SQLite allows CAST(expr AS) with an empty type name (typetoken can be empty)
+ // See https://www.sqlite.org/lang_expr.html
+ sqlite().verified_stmt("SELECT CAST(a AS)");
+
+ // Rejected by dialects without the flag
+ assert!(TestedDialects::new(vec![Box::new(GenericDialect {})])
+ .parse_sql_statements("SELECT CAST(a AS)")
+ .is_err());
+}
+
#[test]
fn parse_n_prefix_not_national_string() {
// In SQLite, `n'...'` is the identifier `n` followed by a string literal.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org