colinmarc commented on code in PR #18187:
URL: https://github.com/apache/datafusion/pull/18187#discussion_r2447441906


##########
datafusion/proto-common/src/from_proto/mod.rs:
##########
@@ -138,11 +138,23 @@ where
     }
 }
 
+impl From<protobuf::ColumnRelation> for TableReference {

Review Comment:
   I think this isn't quite right - usually `From` is just for equivalent 
types, but here we're ignoring half of the input type. I would just call 
`parse_str_normalized` from the `impl From<protobuf::Column> for Column` 
definition.



##########
datafusion/proto-common/src/from_proto/mod.rs:
##########
@@ -138,11 +138,23 @@ where
     }
 }
 
+impl From<protobuf::ColumnRelation> for TableReference {
+    fn from(rel: protobuf::ColumnRelation) -> Self {
+        Self::parse_str_normalized(rel.relation.as_str(), true)
+    }
+}
+
+impl From<&protobuf::ColumnRelation> for TableReference {

Review Comment:
   Same goes for this, but for future reference: you usually don't need to 
implement a separate `From` for a borrowed type, and it's code smell if you do 
(the caller should be forced to use clone explicitly)



##########
datafusion/common/src/table_reference.rs:
##########
@@ -269,24 +269,48 @@ impl TableReference {
     }
 
     /// Forms a [`TableReference`] by parsing `s` as a multipart SQL
-    /// identifier. See docs on [`TableReference`] for more details.
+    /// identifier, normalizing `s` to lowercase.
+    /// See docs on [`TableReference`] for more details.
     pub fn parse_str(s: &str) -> Self {
-        let mut parts = parse_identifiers_normalized(s, false);
+        Self::parse_str_normalized(s, false)
+    }
+
+    /// Forms a [`TableReference`] by parsing `s` as a multipart SQL
+    /// identifier, normalizing `s` to lowercase if `ignore_case` is `false`.
+    /// See docs on [`TableReference`] for more details.
+    pub fn parse_str_normalized(s: &str, ignore_case: bool) -> Self {
+        let table_parts = parse_identifiers_normalized(s, ignore_case);
+
+        Self::from_vec(table_parts)
+             .unwrap_or(Self::Bare { table: s.into() })
+    }
 
+    /// Compose a [`TableReference`] from separate parts. The input vector 
should contain
+    /// at most three elements in the following sequence:
+    /// ```no_rust
+    /// [<catalog>, <schema>, table]
+    /// ```
+    pub fn from_vec(mut parts: Vec<String>) -> Option<Self> {

Review Comment:
   I think this could be `from_parts(parts: &[impl AsRef<str>])` and copy out 
of the slice to be a little bit more flexible. We don't need the `Vec` itself 
(and in fact we destroy it here, which could be surprising to the caller).



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to