viirya commented on code in PR #7719:
URL: https://github.com/apache/datafusion-comet/pull/7719#discussion_r4764361550


##########
native/core/src/parquet/file_error_context.rs:
##########
@@ -42,10 +42,79 @@ use datafusion_datasource::{
 use futures::{stream::BoxStream, StreamExt, TryStreamExt};
 use object_store::ObjectStore;
 use std::{fmt, sync::Arc};
+use url::Url;
 
-/// The original URL-encoded Spark path, before object-store aliases and paths 
are normalized.
+/// The URL-encoded Spark path for diagnostics, with the original scheme and 
without credentials.
 #[derive(Debug, Clone)]
-pub(crate) struct SparkFilePath(pub Arc<str>);
+pub(crate) struct SparkFilePath(Arc<str>);
+
+impl SparkFilePath {
+    pub(crate) fn new(original: &str, url: &Url) -> Self {
+        let path = original.split(['?', '#']).next().unwrap_or_default();
+        if !path.contains('@') {
+            return Self(path.into());
+        }
+        if url.cannot_be_a_base() || path.contains(['\t', '\r', '\n']) {
+            return Self("<redacted>".into());
+        }
+        let (_, rest) = path.split_once(':').unwrap_or_default();
+        let body = rest.trim_start_matches('/');
+        let prefix = &path[..path.len() - body.len()];
+        if url.scheme() == "s3"
+            && url.has_host()
+            && rest.starts_with('/')
+            && !prefix.ends_with("://")
+        {
+            return Self::hostless_alias(prefix, body);
+        }
+        let keep_container = matches!(url.scheme(), "abfs" | "abfss" | "az");
+        if url.password().is_none() && (url.username().is_empty() || 
keep_container) {
+            return Self(path.into());
+        }
+        let authority = body.split('/').next().unwrap_or_default();
+        let Some(at) = authority.rfind('@') else {
+            return Self("<redacted>".into());
+        };
+        let host_and_path = &body[at + 1..];
+        if keep_container && !url.username().is_empty() {
+            Self(format!("{prefix}{}@{host_and_path}", url.username()).into())
+        } else {
+            Self(format!("{prefix}{host_and_path}").into())
+        }
+    }
+
+    // Each segment at depth zero can become the bucket of a hostless S3 alias.
+    // Strip its userinfo even when a later ".." discards it. Keep '@' in 
object keys.
+    fn hostless_alias(prefix: &str, body: &str) -> Self {
+        let mut shown = String::with_capacity(prefix.len() + body.len());
+        shown.push_str(prefix);
+        let mut depth = 0usize;
+        let mut parts = body.split_inclusive('/');
+        while let Some(part) = parts.next() {
+            let segment = part.trim_end_matches('/');
+            if depth == 0 {
+                shown.push_str(part.rsplit_once('@').map_or(part, |(_, host)| 
host));
+            } else {
+                shown.push_str(part);
+            }
+            // url's parent-segment handling keeps a drive letter even on 
non-file URLs.
+            // Once one is reached, the remaining components cannot become the 
bucket.
+            if matches!(segment.as_bytes(), [letter, b':' | b'|'] | [letter, 
b':' | b'|', b'\\', ..] if letter.is_ascii_alphabetic())
+            {
+                shown.extend(parts);
+                break;
+            }
+            match segment {
+                "" if depth == 0 => {}
+                "." | "%2e" | "%2E" => {}
+                ".." | ".%2e" | ".%2E" | "%2e." | "%2E." | "%2e%2e" | "%2e%2E" 
| "%2E%2e"
+                | "%2E%2E" => depth = depth.saturating_sub(1),
+                _ => depth += 1,
+            }
+        }
+        Self(shown.into())
+    }

Review Comment:
   +1. Most inputs this handles can't come from Spark. `file_path` is 
`filePath.toString` from a Hadoop `Path`, which normalizes dot segments and 
quotes `%`. With hadoop-client-api 3.4.2, `s3a:///u:p@bucket/../x/y` becomes 
`s3a:/x/y`, `%2e%2e` becomes `%252e%252e`, and `?sig=1#f` becomes 
`%3Fsig=1%23f`. S3A also rejects login details in the URI 
(`S3xLoginHelper.rejectSecretsInURIs`).
   
   For the hostless case, `rewrite_alias_to_s3` reparses `s3://u:p@bucket/key`, 
so the normalized `url` already holds the userinfo as real userinfo, with `..` 
resolved. `without_credentials(&url)` removes it. `set_scheme` can restore 
`s3a` or the alias, since both are non-special. That would let the table and 
the `?`/`#` planner case shrink to the forms Spark actually sends.
   



##########
native/core/src/parquet/objectstore/s3.rs:
##########
@@ -153,7 +153,10 @@ impl S3StoreTemplate {
         bucket: &str,
     ) -> Result<Self, object_store::Error> {
         let s3_configs = extract_s3_config_options(configs, bucket);
-        debug!("S3 configs for bucket {bucket}: {s3_configs:?}");
+        debug!(

Review Comment:
   Logging only the keys drops the region, path-style and endpoint values, 
which are what you need when debugging an S3-compatible endpoint. Only the 
endpoint can carry userinfo. Could this keep the values and pass just the 
endpoint through `without_credentials`?



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