You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "suxiaogang223 (via GitHub)" <gi...@apache.org> on 2026/07/13 09:46:26 UTC

[I] [Feature] Add write/commit C FFI bindings for bindings/c/ [paimon-rust]

suxiaogang223 opened a new issue, #520:
URL: https://github.com/apache/paimon-rust/issues/520

   ## Background
   
   [Apache Doris](https://github.com/apache/doris) (an MPP OLAP database) is adding Paimon write support. We currently have a working JNI-based write path that bridges to the Paimon Java SDK, but we'd like to add a Rust FFI backend for better performance (zero-copy Arrow, async I/O, no JVM overhead).
   
   The existing `bindings/c/` already provides a complete read-side C FFI (catalog, table, scan, plan, predicate, record batch streaming via Arrow C Data Interface). We'd like to contribute write-side C FFI bindings following the same patterns.
   
   ## Current state
   
   - `bindings/c/` — read-side C FFI ✅ (catalog, table, read builder, scan, plan, predicate, record batch reader)
   - `bindings/python/` — Python bindings with full write support ✅ (`PyWriteBuilder`, `PyTableWrite`, `PyTableCommit`)
   - `bindings/c/` — write-side C FFI ❌ (nothing yet)
   
   ## Proposed API surface
   
   Following the existing naming conventions and opaque handle patterns from `bindings/c/`:
   
   ```
   // === WriteBuilder ===
   paimon_write_builder *paimon_table_new_write_builder(paimon_table *table);
   void paimon_write_builder_free(paimon_write_builder *wb);
   void paimon_write_builder_with_overwrite(paimon_write_builder *wb);
   
   // === TableWrite ===
   paimon_table_write *paimon_write_builder_new_write(paimon_write_builder *wb, paimon_error **err);
   void paimon_table_write_free(paimon_table_write *tw);
   
   // write a single Arrow record batch via C Data Interface (zero-copy)
   paimon_error *paimon_table_write_write_batch(
       paimon_table_write *tw,
       FFI_ArrowArray *array,
       FFI_ArrowSchema *schema);
   
   // close file writers and produce commit messages
   // returns paimon_commit_messages* on success, NULL + err on failure
   paimon_commit_messages *paimon_table_write_prepare_commit(
       paimon_table_write *tw, paimon_error **err);
   
   // === TableCommit ===
   paimon_table_commit *paimon_write_builder_new_commit(paimon_write_builder *wb);
   void paimon_table_commit_free(paimon_table_commit *tc);
   
   paimon_error *paimon_table_commit_commit(
       paimon_table_commit *tc, paimon_commit_messages *msgs);
   paimon_error *paimon_table_commit_overwrite(
       paimon_table_commit *tc, paimon_commit_messages *msgs,
       ... static_partitions ...);
   paimon_error *paimon_table_commit_truncate_table(paimon_table_commit *tc);
   paimon_error *paimon_table_commit_abort(
       paimon_table_commit *tc, paimon_commit_messages *msgs);
   
   // === CommitMessage serialization ===
   // For cross-process transfer, commit messages need serialization.
   // Proposal: use protobuf for schema-safe, language-agnostic serialization,
   // matching Paimon's existing DataFileMeta / CommitMessage struct fields.
   paimon_bytes paimon_commit_messages_serialize(paimon_commit_messages *msgs);
   paimon_commit_messages *paimon_commit_messages_deserialize(
       paimon_bytes data, paimon_error **err);
   void paimon_commit_messages_free(paimon_commit_messages *msgs);
   ```
   
   ## CommitMessage serialization — discussion needed
   
   This is the key open question. Paimon's `CommitMessage` is a Rust struct with nested `Vec<DataFileMeta>`, `Vec<IndexFileMeta>`, etc. For C FFI consumers (like Doris) that need to transfer messages across a process boundary and eventually to a remote coordinator, serialization is required.
   
   Options:
   
   | Format | Pros | Cons |
   |--------|------|------|
   | **Protobuf** | Schema-safe, cross-language, Paimon already uses protobuf internally | Adds `prost-build` dependency to `bindings/c` |
   | **JSON** | Simple, no schema needed | Bulky for DataFileMeta, slower |
   | **FlatBuffers** | Zero-copy deserialization | More complex, less community familiarity |
   | **Paimon binary format** | Reuses existing `CommitMessageSerializer` logic | Java-specific, needs porting to Rust |
   
   We lean toward **Protobuf** — it's the standard approach, Paimon already uses it, and it generates bindings for all languages. But we'd like community input before committing.
   
   ## Implementation plan
   
   1. Add `bindings/c/src/write.rs` with the API surface above
   2. Add CommitMessage protobuf schema and serialization
   3. Add tests under `bindings/c/tests/` (following Python test patterns)
   4. Update `bindings/c/src/lib.rs` to register the new module
   
   ## Questions for the community
   
   1. Does this API surface look reasonable? Any naming or pattern preferences?
   2. **Protobuf vs JSON vs other formats for CommitMessage serialization?**
   3. Should `write_arrow_batch` also accept a batch of batches (`&[RecordBatch]`) or keep it single-batch per call?
   4. Any concerns about adding a protobuf build dependency to `bindings/c/`?
   
   ---
   
   We're happy to implement this and contribute back. Looking forward to your feedback!


-- 
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: issues-unsubscribe@paimon.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Feature] Add write/commit C FFI bindings for bindings/c/ [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi closed issue #520: [Feature] Add write/commit C FFI bindings for bindings/c/
URL: https://github.com/apache/paimon-rust/issues/520


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Feature] Add write/commit C FFI bindings for bindings/c/ [paimon-rust]

Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on issue #520:
URL: https://github.com/apache/paimon-rust/issues/520#issuecomment-4957893184

   @suxiaogang223 Thanks for proposing this. Adding write-side C FFI support is useful for Doris and other native engines, and the overall API looks reasonable.
   
   For the commit message serialization format, @JingsongLi could you help decide whether we should keep compatibility with the existing Java `CommitMessageSerializer` or introduce a new format for Rust FFI?
   
   For Arrow input, one RecordBatch per call should be enough. Please also consider `commit_user` and `commit_identifier` for distributed writes and retries.
   
   Looking forward to the contribution.


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Feature] Add write/commit C FFI bindings for bindings/c/ [paimon-rust]

Posted by "suxiaogang223 (via GitHub)" <gi...@apache.org>.
suxiaogang223 commented on issue #520:
URL: https://github.com/apache/paimon-rust/issues/520#issuecomment-4966863865

   I looked into how the Python bindings handle this, and turns out there is no serialization at all — everything is in-process. `PyCommitMessage` just wraps the Rust `CommitMessage` directly via pyo3, and the code even says "PR1 supports same-process transfer only (no pickle/serialization)". On the storage side, manifests use Apache Avro and snapshots use JSON, no protobuf anywhere.
   
   So I think we can just follow the same pattern for the C FFI: keep it in-process for now, no serialization needed. If cross-process transfer becomes a real requirement later, we can tackle it as a separate enhancement. This should not block the current write-side C FFI work.


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Feature] Add write/commit C FFI bindings for bindings/c/ [paimon-rust]

Posted by "suxiaogang223 (via GitHub)" <gi...@apache.org>.
suxiaogang223 commented on issue #520:
URL: https://github.com/apache/paimon-rust/issues/520#issuecomment-4966858421

   ## Serialization 调研结论
   
   查看了 Python bindings 的实现,**CommitMessage 序列化不会阻塞 C FFI 的开发**:
   
   ### Python 侧现状
   - Python bindings 完全不做 CommitMessage 序列化,纯 in-process 传递
   - `PyCommitMessage` 通过 pyo3 直接持有 Rust 的 `CommitMessage` 内存对象
   - 代码注释明确写:*"PR1 supports same-process transfer only (no pickle/serialization)"*
   - 底层存储格式用的是:
     - Manifest 文件 → **Apache Avro** 二进制
     - Snapshot 元数据 → **Serde JSON**
     - 没有任何地方使用 protobuf
   
   ### 建议
   C FFI 可以采用和 Python 完全一致的 in-process 方式,不引入序列化层。如果未来真的需要跨进程传输 commit messages,可以作为独立的功能增强来考量。
   
   这样 CommitMessage 序列化问题不用阻塞当前 write-side C FFI 的开发,可以参照 Python 路径先做 in-process 版本。


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org