ZENOTME commented on code in PR #1465:
URL: https://github.com/apache/paimon-rust/pull/1465#discussion_r4675775116


##########
crates/paimon/src/io/file_io.rs:
##########
@@ -110,6 +110,17 @@ pub trait FileIOProvider: std::fmt::Debug + Send + Sync + 
'static {
         let (op, relative_path) = self.create(path).await?;
         Ok((op, relative_path, None))
     }
+
+    /// Whether opening a file for writing requires calling `create_dir` on its
+    /// parent directory first.
+    ///
+    /// Defaults to `true` for compatibility with hierarchical backends that
+    /// require parent directories to exist before writing. Providers backed by
+    /// object stores or operators that create missing parent directories on
+    /// write may return `false` to avoid extra directory marker requests.
+    fn requires_parent_dir_for_write(&self) -> bool {

Review Comment:
   I've pushed commit b909c784 removing `requires_parent_dir_for_write()` from 
`FileIOProvider` completely. This implements **Option 2** below (preserving 
backward compatibility without changing any public trait). I'd also like to 
share **Option 1** in case we prefer to simplify further:
   
   **Option 2 (Implemented in the latest push — no public API change, keeps 
backward compatibility):**
   - Removed `requires_parent_dir_for_write()` from `pub trait FileIOProvider`.
   - Moved the flag to a crate-internal field on `FileIOBackend::Provider` / 
`FileSource::Provider`: built-in `Storage` backends (except `CustomFs` and 
`Memory`) and internal providers (`RESTTokenFileIO`, `FuseFileIO`) inherit the 
backend's behavior via a `pub(crate)` helper (`with_internal_provider`), while 
external custom `FileIOProvider`s and `CustomFs` keep the conservative 
pre-write parent-directory creation path.
   
   **Option 1 (Simpler alternative — delegate parent directory creation to the 
OpenDAL `Operator`):**
   - Drop pre-write parent directory creation in 
`OutputFile::resolve_for_write()` completely (no backend special-casing), and 
document on `FileIOProvider` that resolving/opening a file for writing should 
not require callers to call `mkdirs()` first (updating the `memory` 
empty-directory assertion in `consumer_manager` tests if needed).
   - Why Option 1 is worth considering:
     1. **Clearer layering (I/O / operator responsibility, aligned with OpenDAL 
and `iceberg-rust`)**: Whether a backend needs missing parent directories 
before creating a file is a storage-service detail, not a table-format or 
writer concern. OpenDAL's hierarchical services already handle this inside 
their write paths (`FsWriter::create` via `ensure_write_abs_path`, `HdfsCore` 
via `ensure_parent_dir`, `HdfsNative` via HDFS `create_parent = true`, and 
`WebdavWriter` via `webdav_mkcol` by default), while object stores don't need 
directory markers. `iceberg-rust` follows the same model and delegates 
`OutputFile::writer()` directly to OpenDAL `Operator::writer()` without calling 
`create_dir`.
     2. **Questionable precondition on `FileIOProvider::create(path)`**: 
Guaranteeing that callers have already created the parent directory before 
calling `FileIOProvider::create(path)` is not a necessary or intended semantic 
of `FileIOProvider::create(path)` — it is meant to resolve an `(Operator, 
relative_path)` for a URI, not to rely on physical parent directories already 
existing. Maintaining this implicit precondition forces `resolve_for_write()` 
to split the logical parent URI, call `provider.create(parent/)`, and issue 
`create_dir` before even resolving the target file path. Is this implicit 
semantic really worth maintaining?
     3. **Consistent behavior for external object-store providers**: Without a 
public trait knob, Option 2 has an inherent asymmetry — built-in S3 / 
`RESTTokenFileIO` skip directory-marker PUTs, whereas an external custom S3 
`FileIOProvider` (like `SharedS3Provider`) still pays for an extra 
directory-marker PUT on every write. Option 1 gives both built-in and external 
providers the same behavior with much less code.
   
   If you'd like to keep strict backward compatibility for existing custom 
`FileIOProvider`s, the current push (Option 2) is ready as-is. If you prefer 
the cleaner Option 1 contract, I'm happy to simplify it accordingly.



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

Reply via email to