benbellick commented on code in PR #19729:
URL: https://github.com/apache/datafusion/pull/19729#discussion_r2848770501
##########
datafusion/substrait/src/logical_plan/consumer/rel/read_rel.rs:
##########
@@ -176,45 +176,100 @@ pub async fn from_read_rel(
}))
}
Some(ReadType::LocalFiles(lf)) => {
- fn extract_filename(name: &str) -> Option<String> {
- let corrected_url =
- if name.starts_with("file://") &&
!name.starts_with("file:///") {
- name.replacen("file://", "file:///", 1)
- } else {
- name.to_string()
- };
-
- Url::parse(&corrected_url).ok().and_then(|url| {
- let path = url.path();
- std::path::Path::new(path)
- .file_name()
- .map(|filename| filename.to_string_lossy().to_string())
- })
+ /// Extracts the path string from a PathType variant.
+ /// Normalizes file:// URLs to file:/// format for proper URL
parsing.
+ fn extract_path(path_type: Option<&PathType>) -> Option<String> {
+ let path_str = match path_type? {
+ PathType::UriPath(p) => p.clone(),
+ PathType::UriPathGlob(p) => p.clone(),
+ PathType::UriFile(p) => p.clone(),
+ PathType::UriFolder(p) => p.clone(),
+ };
+
+ // Normalize file:// to file:/// for proper URL parsing
+ let normalized = if path_str.starts_with("file://")
+ && !path_str.starts_with("file:///")
+ {
+ path_str.replacen("file://", "file:///", 1)
+ } else {
+ path_str
+ };
Review Comment:
Hmm to me that sounds like a bug on the consumer side too then. We should
only produce plans with valid URIs IMO.
I'm not the datafusion expert, so I'm not sure the right approach here but I
feel like it would be better to fix that bug rather than allow the incorrect
substrait in the producer require accommodation in all of the consumer parts of
the code.
--
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]