This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 8e49e1dd feat(bindings): expose tag retention through C and Go APIs 
(#1368)
8e49e1dd is described below

commit 8e49e1dd12215fee9db95e418709a5729c4511a0
Author: AuroraVoyage <[email protected]>
AuthorDate: Wed Nov 11 10:57:20 2026 +0800

    feat(bindings): expose tag retention through C and Go APIs (#1368)
---
 bindings/c/src/catalog.rs             | 39 +++++++++++++++++++++++-
 bindings/c/src/tests.rs               | 56 +++++++++++++++++++++++++++++++++++
 bindings/go/catalog_tag.go            | 34 +++++++++++++++++++--
 bindings/go/tests/catalog_tag_test.go | 46 +++++++++++++++++++++++++++-
 docs/src/go-binding.md                | 25 ++++++++++++++--
 5 files changed, 193 insertions(+), 7 deletions(-)

diff --git a/bindings/c/src/catalog.rs b/bindings/c/src/catalog.rs
index 844119da..ba2fdeba 100644
--- a/bindings/c/src/catalog.rs
+++ b/bindings/c/src/catalog.rs
@@ -227,6 +227,34 @@ pub unsafe extern "C" fn paimon_catalog_create_tag(
     tag_name: *const c_char,
     snapshot_id: *const i64,
     ignore_if_exists: bool,
+) -> *mut paimon_error {
+    paimon_catalog_create_tag_with_retention(
+        catalog,
+        identifier,
+        tag_name,
+        snapshot_id,
+        std::ptr::null(),
+        ignore_if_exists,
+    )
+}
+
+/// Create a tag with an optional retention duration such as `"1d"` or `"12h"`.
+///
+/// Pass a null `time_retained` to create a tag without retention metadata.
+///
+/// # Safety
+/// `catalog` and `identifier` must be valid pointers from previous paimon C 
calls.
+/// `tag_name` must be a valid null-terminated C string.
+/// If non-null, `snapshot_id` must point to a valid `i64`.
+/// If non-null, `time_retained` must be a valid null-terminated C string.
+#[no_mangle]
+pub unsafe extern "C" fn paimon_catalog_create_tag_with_retention(
+    catalog: *const paimon_catalog,
+    identifier: *const paimon_identifier,
+    tag_name: *const c_char,
+    snapshot_id: *const i64,
+    time_retained: *const c_char,
+    ignore_if_exists: bool,
 ) -> *mut paimon_error {
     if let Err(error) = check_non_null(catalog, "catalog") {
         return error;
@@ -238,14 +266,23 @@ pub unsafe extern "C" fn paimon_catalog_create_tag(
         Ok(tag_name) => tag_name,
         Err(error) => return error,
     };
+    let time_retained = if time_retained.is_null() {
+        None
+    } else {
+        match validate_cstr(time_retained, "time_retained") {
+            Ok(value) => Some(value),
+            Err(error) => return error,
+        }
+    };
 
     let catalog = &*((*catalog).inner as *const Arc<dyn Catalog>);
     let identifier = &*((*identifier).inner as *const Identifier);
     let snapshot_id = snapshot_id.as_ref().copied();
-    match runtime().block_on(catalog.create_tag(
+    match runtime().block_on(catalog.create_tag_with_retention(
         identifier,
         &tag_name,
         snapshot_id,
+        time_retained.as_deref(),
         ignore_if_exists,
     )) {
         Ok(()) => std::ptr::null_mut(),
diff --git a/bindings/c/src/tests.rs b/bindings/c/src/tests.rs
index ea7d0d4f..3497cb98 100644
--- a/bindings/c/src/tests.rs
+++ b/bindings/c/src/tests.rs
@@ -1130,6 +1130,7 @@ fn test_catalog_tag_lifecycle() {
         let tag: paimon::api::GetTagResponse = 
serde_json::from_slice(tag_json).unwrap();
         assert_eq!(tag.tag_name, "release-1");
         assert_eq!(tag.snapshot.id(), 1);
+        assert!(tag.tag_time_retained.is_none());
 
         let explicit_name = CString::new("release-explicit").unwrap();
         let snapshot_id = 1;
@@ -1141,6 +1142,58 @@ fn test_catalog_tag_lifecycle() {
             false,
         );
         assert!(error.is_null());
+        let explicit_result =
+            paimon_catalog_get_tag(catalog, identifier.identifier, 
explicit_name.as_ptr());
+        assert!(explicit_result.error.is_null());
+        let explicit_json =
+            std::slice::from_raw_parts(explicit_result.tag.data, 
explicit_result.tag.len);
+        let explicit: paimon::api::GetTagResponse = 
serde_json::from_slice(explicit_json).unwrap();
+        assert!(explicit.tag_time_retained.is_none());
+        paimon_bytes_free(explicit_result.tag);
+
+        let retained_name = CString::new("release-retained").unwrap();
+        let time_retained = CString::new("1d").unwrap();
+        let error = paimon_catalog_create_tag_with_retention(
+            catalog,
+            identifier.identifier,
+            retained_name.as_ptr(),
+            &snapshot_id,
+            time_retained.as_ptr(),
+            false,
+        );
+        assert!(error.is_null());
+        let retained_result =
+            paimon_catalog_get_tag(catalog, identifier.identifier, 
retained_name.as_ptr());
+        assert!(retained_result.error.is_null());
+        let retained_json =
+            std::slice::from_raw_parts(retained_result.tag.data, 
retained_result.tag.len);
+        let retained: paimon::api::GetTagResponse = 
serde_json::from_slice(retained_json).unwrap();
+        assert_eq!(retained.tag_name, "release-retained");
+        assert_eq!(retained.snapshot.id(), 1);
+        assert_eq!(retained.tag_time_retained.as_deref(), Some("PT24H"));
+        assert!(retained.tag_create_time.is_some());
+        paimon_bytes_free(retained_result.tag);
+
+        let invalid_name = CString::new("release-invalid").unwrap();
+        let invalid_retained = CString::new("-1d").unwrap();
+        let invalid = paimon_catalog_create_tag_with_retention(
+            catalog,
+            identifier.identifier,
+            invalid_name.as_ptr(),
+            &snapshot_id,
+            invalid_retained.as_ptr(),
+            false,
+        );
+        assert_eq!((*invalid).code, PaimonErrorCode::InvalidInput as i32);
+        paimon_error_free(invalid);
+        let missing_invalid =
+            paimon_catalog_get_tag(catalog, identifier.identifier, 
invalid_name.as_ptr());
+        assert_eq!(
+            (*missing_invalid.error).code,
+            PaimonErrorCode::NotFound as i32
+        );
+        paimon_error_free(missing_invalid.error);
+
         let missing_snapshot_id = 2;
         let missing_snapshot_name = CString::new("missing-snapshot").unwrap();
         let missing = paimon_catalog_create_tag(
@@ -1176,6 +1229,9 @@ fn test_catalog_tag_lifecycle() {
         let error =
             paimon_catalog_delete_tag(catalog, identifier.identifier, 
explicit_name.as_ptr());
         assert!(error.is_null());
+        let error =
+            paimon_catalog_delete_tag(catalog, identifier.identifier, 
retained_name.as_ptr());
+        assert!(error.is_null());
 
         paimon_bytes_free(tag_result.tag);
         paimon_identifier_free(identifier.identifier);
diff --git a/bindings/go/catalog_tag.go b/bindings/go/catalog_tag.go
index 594c4901..bb12b946 100644
--- a/bindings/go/catalog_tag.go
+++ b/bindings/go/catalog_tag.go
@@ -69,6 +69,18 @@ func (c *Catalog) CreateTag(
        tagName string,
        snapshotID *int64,
        ignoreIfExists bool,
+) error {
+       return c.CreateTagWithRetention(id, tagName, snapshotID, nil, 
ignoreIfExists)
+}
+
+// CreateTagWithRetention creates a tag with an optional retention duration 
such as "1d".
+// Pass nil timeRetained to create a tag without retention metadata.
+func (c *Catalog) CreateTagWithRetention(
+       id Identifier,
+       tagName string,
+       snapshotID *int64,
+       timeRetained *string,
+       ignoreIfExists bool,
 ) error {
        if c.inner == nil {
                return ErrClosed
@@ -78,11 +90,12 @@ func (c *Catalog) CreateTag(
                return err
        }
        defer ffiIdentifierFree.symbol(c.ctx)(cID)
-       return ffiCatalogCreateTag.symbol(c.ctx)(
+       return ffiCatalogCreateTagWithRetention.symbol(c.ctx)(
                c.inner,
                cID,
                tagName,
                snapshotID,
+               timeRetained,
                ignoreIfExists,
        )
 }
@@ -113,14 +126,15 @@ func (c *Catalog) DeleteTag(id Identifier, tagName 
string) error {
        return ffiCatalogDeleteTag.symbol(c.ctx)(c.inner, cID, tagName)
 }
 
-var ffiCatalogCreateTag = newFFI(ffiOpts{
-       sym:   "paimon_catalog_create_tag",
+var ffiCatalogCreateTagWithRetention = newFFI(ffiOpts{
+       sym:   "paimon_catalog_create_tag_with_retention",
        rType: &ffi.TypePointer,
        aTypes: []*ffi.Type{
                &ffi.TypePointer,
                &ffi.TypePointer,
                &ffi.TypePointer,
                &ffi.TypePointer,
+               &ffi.TypePointer,
                &ffi.TypeUint8,
        },
 }, func(ctx context.Context, ffiCall ffiCall) func(
@@ -128,6 +142,7 @@ var ffiCatalogCreateTag = newFFI(ffiOpts{
        *paimonIdentifier,
        string,
        *int64,
+       *string,
        bool,
 ) error {
        return func(
@@ -135,6 +150,7 @@ var ffiCatalogCreateTag = newFFI(ffiOpts{
                id *paimonIdentifier,
                tagName string,
                snapshotID *int64,
+               timeRetained *string,
                ignoreIfExists bool,
        ) error {
                tagNamePtr, err := bytePtrFromString(tagName)
@@ -145,6 +161,15 @@ var ffiCatalogCreateTag = newFFI(ffiOpts{
                if snapshotID != nil {
                        snapshotIDPtr = unsafe.Pointer(snapshotID)
                }
+               var timeRetainedPtr unsafe.Pointer
+               var timeRetainedBytes *byte
+               if timeRetained != nil {
+                       timeRetainedBytes, err = 
bytePtrFromString(*timeRetained)
+                       if err != nil {
+                               return err
+                       }
+                       timeRetainedPtr = unsafe.Pointer(timeRetainedBytes)
+               }
                ignore := uint8(0)
                if ignoreIfExists {
                        ignore = 1
@@ -156,10 +181,13 @@ var ffiCatalogCreateTag = newFFI(ffiOpts{
                        unsafe.Pointer(&id),
                        unsafe.Pointer(&tagNamePtr),
                        unsafe.Pointer(&snapshotIDPtr),
+                       unsafe.Pointer(&timeRetainedPtr),
                        unsafe.Pointer(&ignore),
                )
                runtime.KeepAlive(tagNamePtr)
                runtime.KeepAlive(snapshotID)
+               runtime.KeepAlive(timeRetainedBytes)
+               runtime.KeepAlive(timeRetained)
                return parseError(ctx, ffiError)
        }
 })
diff --git a/bindings/go/tests/catalog_tag_test.go 
b/bindings/go/tests/catalog_tag_test.go
index 112c17e4..732bac8c 100644
--- a/bindings/go/tests/catalog_tag_test.go
+++ b/bindings/go/tests/catalog_tag_test.go
@@ -64,6 +64,9 @@ func TestCatalogTagLifecycle(t *testing.T) {
        if tag.TagName != "release-1" || tag.Snapshot.ID != 1 {
                t.Fatalf("unexpected tag: %#v", tag)
        }
+       if tag.TagTimeRetained != nil {
+               t.Fatalf("plain CreateTag retention = %#v, want nil", 
tag.TagTimeRetained)
+       }
        if tag.Snapshot.CommitKind != paimon.CommitKindAppend {
                t.Fatalf("commit kind = %q, want %q", tag.Snapshot.CommitKind, 
paimon.CommitKindAppend)
        }
@@ -79,9 +82,44 @@ func TestCatalogTagLifecycle(t *testing.T) {
        if err := catalog.CreateTag(id, "release-explicit", &snapshotID, 
false); err != nil {
                t.Fatal(err)
        }
+       explicit, err := catalog.GetTag(id, "release-explicit")
+       if err != nil {
+               t.Fatal(err)
+       }
+       if explicit.TagTimeRetained != nil {
+               t.Fatalf("explicit CreateTag retention = %#v, want nil", 
explicit.TagTimeRetained)
+       }
 
-       err = catalog.CreateTag(id, "release-1", nil, false)
+       timeRetained := "1d"
+       if err := catalog.CreateTagWithRetention(id, "release-retained", 
&snapshotID, &timeRetained, false); err != nil {
+               t.Fatal(err)
+       }
+       retained, err := catalog.GetTag(id, "release-retained")
+       if err != nil {
+               t.Fatal(err)
+       }
+       if retained.TagName != "release-retained" || retained.Snapshot.ID != 1 {
+               t.Fatalf("unexpected retained tag: %#v", retained)
+       }
+       if retained.TagTimeRetained == nil || *retained.TagTimeRetained != 
"PT24H" {
+               t.Fatalf("tag time retained = %#v, want PT24H", 
retained.TagTimeRetained)
+       }
+       if retained.TagCreateTime == nil {
+               t.Fatal("expected tag create time for retained tag")
+       }
+
+       invalidRetained := "-1d"
+       err = catalog.CreateTagWithRetention(id, "release-invalid", 
&snapshotID, &invalidRetained, false)
        var paimonErr *paimon.Error
+       if !errors.As(err, &paimonErr) || paimonErr.Code() != 
paimon.CodeInvalidInput {
+               t.Fatalf("invalid retention error = %v", err)
+       }
+       _, err = catalog.GetTag(id, "release-invalid")
+       if !errors.As(err, &paimonErr) || paimonErr.Code() != 
paimon.CodeNotFound {
+               t.Fatalf("invalid retention should not create tag: %v", err)
+       }
+
+       err = catalog.CreateTag(id, "release-1", nil, false)
        if !errors.As(err, &paimonErr) || paimonErr.Code() != 
paimon.CodeAlreadyExist {
                t.Fatalf("duplicate tag error = %v", err)
        }
@@ -103,11 +141,17 @@ func TestCatalogTagLifecycle(t *testing.T) {
        if err := catalog.DeleteTag(id, "release-explicit"); err != nil {
                t.Fatal(err)
        }
+       if err := catalog.DeleteTag(id, "release-retained"); err != nil {
+               t.Fatal(err)
+       }
 
        catalog.Close()
        if err := catalog.CreateTag(id, "closed", nil, false); !errors.Is(err, 
paimon.ErrClosed) {
                t.Fatalf("closed catalog error = %v", err)
        }
+       if err := catalog.CreateTagWithRetention(id, "closed-retained", nil, 
&timeRetained, false); !errors.Is(err, paimon.ErrClosed) {
+               t.Fatalf("closed catalog CreateTagWithRetention error = %v", 
err)
+       }
 }
 
 func TestCatalogListDatabasesAndTables(t *testing.T) {
diff --git a/docs/src/go-binding.md b/docs/src/go-binding.md
index 919a871b..a343fb6e 100644
--- a/docs/src/go-binding.md
+++ b/docs/src/go-binding.md
@@ -332,8 +332,29 @@ snapshotID := int64(123)
 err := catalog.CreateTag(id, "dataset-43", &snapshotID, false)
 ```
 
-The final argument to `CreateTag` ignores an existing tag. Creating tags with
-a retention duration is not yet supported.
+The final argument to `CreateTag` ignores an existing tag.
+
+Create a tag with retention using duration strings such as `"1d"`, `"12h"`, or
+`"30min"`. Retention is persisted on the tag file; this API does not expire 
tags
+automatically. `GetTag` returns the retention as an ISO-8601 duration (for
+example `"1d"` becomes `"PT24H"`):
+
+```go
+snapshotID := int64(123)
+timeRetained := "1d"
+err := catalog.CreateTagWithRetention(id, "dataset-44", &snapshotID, 
&timeRetained, false)
+if err != nil {
+    log.Fatal(err)
+}
+tag, err := catalog.GetTag(id, "dataset-44")
+if err != nil {
+    log.Fatal(err)
+}
+log.Printf("retained for %s", *tag.TagTimeRetained)
+```
+
+Pass `nil` for `timeRetained` to create a tag without retention metadata, the
+same as `CreateTag`.
 
 ## Writing a Table
 

Reply via email to