You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by lu...@apache.org on 2026/09/22 10:57:00 UTC
(datafusion-sqlparser-rs) branch compound-field-access-number-spacing updated (17f64b5e5 -> cbd75aca2)
This is an automated email from the ASF dual-hosted git repository.
LucaCappelletti94 pushed a change to branch compound-field-access-number-spacing
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
discard 17f64b5e5 Generic: Add spacing around dot in compound field access adjacent to numbers
new cbd75aca2 Generic: Add spacing around dot in compound field access adjacent to numbers
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (17f64b5e5)
\
N -- N -- N refs/heads/compound-field-access-number-spacing (cbd75aca2)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
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.
Summary of changes:
tests/sqlparser_common.rs | 3 ---
1 file changed, 3 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion-sqlparser-rs) 01/01: Generic: Add spacing around dot in compound field access adjacent to numbers
Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
LucaCappelletti94 pushed a commit to branch compound-field-access-number-spacing
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit cbd75aca266552781cecde237fcffa70e9af2c9a
Author: LucaCappelletti94 <ca...@gmail.com>
AuthorDate: Tue Sep 22 10:26:10 2026 +0200
Generic: Add spacing around dot in compound field access adjacent to numbers
---
src/ast/mod.rs | 25 +++++++++++++++++++++----
tests/sqlparser_common.rs | 19 +++++++++++++++++++
2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index dcfd1a96e..adabf7602 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -1484,12 +1484,14 @@ pub enum AccessExpr {
Subscript(Subscript),
}
+const fn is_number_expr(expr: &Expr) -> bool {
+ matches!(expr, Expr::Value(v) if matches!(v.value, Value::Number(_, _)))
+}
+
impl fmt::Display for AccessExpr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
- AccessExpr::Dot(Expr::Value(value)) if matches!(value.value, Value::Number(_, _)) => {
- write!(f, " . {value}")
- }
+ AccessExpr::Dot(expr) if is_number_expr(expr) => write!(f, " . {expr}"),
AccessExpr::Dot(expr) => write!(f, ".{expr}"),
AccessExpr::Subscript(subscript) => write!(f, "[{subscript}]"),
}
@@ -1751,8 +1753,23 @@ impl fmt::Display for Expr {
Expr::CompoundIdentifier(s) => write!(f, "{}", display_separated(s, ".")),
Expr::CompoundFieldAccess { root, access_chain } => {
write!(f, "{root}")?;
+ let mut prev_is_number = is_number_expr(root);
for field in access_chain {
- write!(f, "{field}")?;
+ match field {
+ AccessExpr::Dot(expr) => {
+ let curr_is_number = is_number_expr(expr);
+ if prev_is_number || curr_is_number {
+ write!(f, " . {expr}")?;
+ } else {
+ write!(f, ".{expr}")?;
+ }
+ prev_is_number = curr_is_number;
+ }
+ AccessExpr::Subscript(subscript) => {
+ write!(f, "[{subscript}]")?;
+ prev_is_number = false;
+ }
+ }
}
Ok(())
}
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index c4aa607d8..6408253b5 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -20080,3 +20080,22 @@ fn parse_unary_minus_never_renders_line_comment() {
all_dialects().verified_stmt("SELECT -1");
all_dialects().verified_stmt("SELECT -x");
}
+
+#[test]
+fn parse_compound_field_access_numeric_display() {
+ all_dialects().verified_stmt("SELECT 1 . i");
+ all_dialects().verified_stmt("SELECT (1 . i)");
+ all_dialects().verified_stmt("SELECT 1 . 2");
+ all_dialects().verified_stmt("SELECT (a . 1 . b)");
+ all_dialects().verified_stmt("SELECT 1 . i.j");
+ all_dialects().verified_stmt("SELECT 1 . 2 . 3");
+ all_dialects().verified_stmt("SELECT a.b.c");
+
+ let err = all_dialects_where(|d| !d.supports_numeric_prefix())
+ .parse_sql_statements("SELECT (1.i)")
+ .unwrap_err();
+ assert_eq!(
+ err,
+ ParserError::ParserError("Expected: ), found: i".to_string())
+ );
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org