Jefffrey commented on code in PR #5625:
URL: https://github.com/apache/arrow-datafusion/pull/5625#discussion_r1142659282


##########
datafusion/common/src/column.rs:
##########
@@ -112,12 +114,18 @@ impl Column {
 
     /// Serialize column into a quoted flat name string
     pub fn quoted_flat_name(&self) -> String {
-        // TODO: quote identifiers only when special characters present
-        // see: https://github.com/apache/arrow-datafusion/issues/5523
         match &self.relation {
             Some(r) => {
-                format!("{}.{}", r.to_quoted_string(), 
quote_identifier(&self.name))
+                let regexp = Regex::new(r"^[a-zA-Z][_a-zA-Z0-9]*$").unwrap();
+                let column_name = if regexp.is_match(&self.name) {
+                    self.name.clone()
+                } else {
+                    quote_identifier(&self.name)
+                };
+
+                format!("{}.{}", r.to_quoted_string(), column_name)

Review Comment:
   probably worth a follow on pr to handle similar logic in 
`to_quoted_string()` for `TableReference`



##########
datafusion/common/src/column.rs:
##########
@@ -112,12 +114,18 @@ impl Column {
 
     /// Serialize column into a quoted flat name string
     pub fn quoted_flat_name(&self) -> String {
-        // TODO: quote identifiers only when special characters present
-        // see: https://github.com/apache/arrow-datafusion/issues/5523
         match &self.relation {
             Some(r) => {
-                format!("{}.{}", r.to_quoted_string(), 
quote_identifier(&self.name))
+                let regexp = Regex::new(r"^[a-zA-Z][_a-zA-Z0-9]*$").unwrap();

Review Comment:
   should lazy static the regex initialization itself i think, e.g. 
https://github.com/apache/arrow-datafusion/blob/26e1b20ea3362ea62cb713004a0636b8af6a16d7/datafusion/physical-expr/src/regex_expressions.rs#L82-L84
   
   regarding the regex itself, i think identifiers are allowed to start with 
underscore, and if they have capitalized letters then they should be quoted, so 
regex would be like `^[_a-z][_a-z0-9]*$`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to