comphead commented on code in PR #7777:
URL: https://github.com/apache/datafusion-comet/pull/7777#discussion_r4743962680


##########
native/core/src/execution/operators/parquet_writer.rs:
##########
@@ -572,6 +572,55 @@ impl ParquetWriterExec {
     }
 }
 
+impl Debug for ParquetWriterExec {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        f.debug_struct("ParquetWriterExec")
+            .field("input", &self.input)
+            .field("output_path", &RedactedPath(&self.output_path))
+            .field("compression", &self.compression)
+            .field("partition_id", &self.partition_id)
+            .field("column_names", &self.column_names)
+            .field("output_schema", &self.output_schema)
+            .field("spark_version", &self.spark_version)
+            .field(
+                "object_store_options",
+                &RedactedOptions(&self.object_store_options),
+            )
+            .field("output_stream", &self.output_stream)
+            .field("metrics", &self.metrics)
+            .field("cache", &self.cache)
+            .finish()
+    }
+}
+
+/// Drops the userinfo and query, which can hold a password, access key ID or 
SAS token.
+struct RedactedPath<'a>(&'a str);
+
+impl Debug for RedactedPath<'_> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        match Url::parse(self.0) {
+            Ok(url) => Debug::fmt(without_credentials(&url).as_str(), f),
+            // Credentials cannot be stripped from a path that does not parse.
+            Err(_) => f.write_str("<unparseable>"),
+        }
+    }
+}
+
+/// Shows the option keys but not their values, which can hold object store 
credentials.
+struct RedactedOptions<'a>(&'a HashMap<String, String>);

Review Comment:
   `RedactedOptions` is a second copy of `RedactedProperties` in 
`native/core/src/execution/operators/iceberg_scan.rs` line 567, and the only 
difference is the key sort. The sort is also the better behavior for a 
`HashMap`, since the iceberg one prints keys in random order. Add one shared 
wrapper where both operators can import it (for example next to the other 
operators' helpers in `operators/mod.rs`), have `IcebergScanExec` use it too, 
and delete both private copies. Two copies will drift the next time a third 
operator needs the same redaction.



##########
native/core/src/execution/operators/parquet_writer.rs:
##########
@@ -572,6 +572,55 @@ impl ParquetWriterExec {
     }
 }
 
+impl Debug for ParquetWriterExec {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        f.debug_struct("ParquetWriterExec")
+            .field("input", &self.input)
+            .field("output_path", &RedactedPath(&self.output_path))
+            .field("compression", &self.compression)
+            .field("partition_id", &self.partition_id)
+            .field("column_names", &self.column_names)
+            .field("output_schema", &self.output_schema)
+            .field("spark_version", &self.spark_version)
+            .field(
+                "object_store_options",
+                &RedactedOptions(&self.object_store_options),
+            )
+            .field("output_stream", &self.output_stream)
+            .field("metrics", &self.metrics)
+            .field("cache", &self.cache)
+            .finish()
+    }
+}
+
+/// Drops the userinfo and query, which can hold a password, access key ID or 
SAS token.
+struct RedactedPath<'a>(&'a str);
+
+impl Debug for RedactedPath<'_> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        match Url::parse(self.0) {
+            Ok(url) => Debug::fmt(without_credentials(&url).as_str(), f),
+            // Credentials cannot be stripped from a path that does not parse.
+            Err(_) => f.write_str("<unparseable>"),

Review Comment:
   `without_credentials` also drops the username, which for `abfs`, `abfss`, 
`wasb` and `az` URLs is the container (see the doc comment on `without_secrets` 
in `native/core/src/parquet/objectstore/url_redaction.rs`). The debug path for 
`abfss://[email protected]/x` then loses the container, 
which `without_secrets` would keep. Question: is losing it acceptable for a 
diagnostic string, or should the choice follow the scheme as 
`parquet_support.rs` line 1089 does for `az`?



##########
native/core/src/execution/operators/parquet_writer.rs:
##########
@@ -1418,6 +1467,30 @@ mod tests {
         );
     }
 
+    #[test]
+    fn test_parquet_writer_debug_redacts_credentials() -> Result<()> {
+        let schema = Arc::new(Schema::new(vec![Field::new("id", 
DataType::Int32, true)]));
+        let memory_source = MemorySourceConfig::try_new(&[vec![]], 
Arc::clone(&schema), None)?;
+        let writer = ParquetWriterExec::try_new(
+            Arc::new(DataSourceExec::new(Arc::new(memory_source))),
+            
"s3a://AKIDEXAMPLE:s3cretpw@bucket/part-00000.parquet?sig=sastoken".to_string(),
+            ParquetCompression::None,
+            0,
+            vec!["id".to_string()],
+            None,
+            HashMap::from([("fs.s3a.secret.key".to_string(), 
"supersecret".to_string())]),
+        )?;
+
+        let debug = format!("{writer:?}");
+        assert!(debug.contains("s3a://bucket/part-00000.parquet"), "{debug}");
+        assert!(debug.contains("fs.s3a.secret.key"), "{debug}");
+        for secret in ["AKIDEXAMPLE", "s3cretpw", "sastoken", "supersecret"] {

Review Comment:
   The `<unparseable>` branch is the only part of the new code that the test 
does not reach. A second path such as 
`s3a://AKIDEXAMPLE:s3cretpw@host:notaport/part.parquet` (rejected by 
`Url::parse` with an invalid port) would check that the fallback prints no 
secret. I did not run this. A fragment on the first URL would cover the 
`set_fragment` case in the same test.



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