comphead commented on code in PR #7719:
URL: https://github.com/apache/datafusion-comet/pull/7719#discussion_r4762660835
##########
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:
`SparkFilePath::new` and `hostless_alias` are a second redaction
implementation next to `native/core/src/parquet/objectstore/url_redaction.rs`
(`without_credentials` and `without_secrets`, from
https://github.com/apache/datafusion-comet/pull/7127). Those use
`Url::set_password(None)`, `set_username("")` and clear the query and fragment,
and nothing in this PR calls them. The new code exists to keep Spark's exact
spelling and to handle a hostless alias, where `url` leaves `u:p@bucket` in the
path. It costs about 70 lines that re-implement the `url` crate's dot-segment
and drive-letter handling by hand, so a difference from `url`'s rules either
leaks a segment or hides one. The follow-up rounds on `..` and drive letters
show how easy that is to get wrong.
A smaller design, which I did not run: keep the fast path for paths without
`@`, which preserves Spark's spelling. Otherwise build the text from
`without_credentials` on `Url::parse(original)`, or `without_secrets` for
`abfs`, `abfss` and `az` to keep the container. For a hostless alias, use the
normalized `url` the caller already has (`s3://bucket/key`) with
`without_credentials`, since its host is the bucket the reader uses. Only paths
that carried credentials would then show the `url` crate's canonical spelling.
That would drop `hostless_alias`, the `rfind('@')` slicing and both
`<redacted>` fallbacks.
If the exact spelling matters even for those paths, please move this logic
into `url_redaction.rs` so one module decides what a diagnostic URL may show.
--
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]