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 c23bc83e feat(go): expose catalog table deletion (#1471)
c23bc83e is described below
commit c23bc83e22ab86eda382f2b4d7f197dd1f7e957f
Author: ZENOTME <[email protected]>
AuthorDate: Fri Nov 20 22:14:52 2026 +0800
feat(go): expose catalog table deletion (#1471)
---
bindings/c/src/catalog.rs | 26 ++++++++++++++
bindings/go/catalog.go | 29 ++++++++++++++++
bindings/go/tests/catalog_drop_test.go | 62 ++++++++++++++++++++++++++++++++++
docs/src/go-binding.md | 6 ++++
4 files changed, 123 insertions(+)
diff --git a/bindings/c/src/catalog.rs b/bindings/c/src/catalog.rs
index b94a0dfe..1f9475e3 100644
--- a/bindings/c/src/catalog.rs
+++ b/bindings/c/src/catalog.rs
@@ -236,6 +236,32 @@ pub unsafe extern "C" fn paimon_catalog_get_table(
}
}
+/// Drop a table. Returns null on success, or an error to free with
+/// `paimon_error_free`. If `ignore_if_not_exists` is true, a missing table is
accepted.
+///
+/// # Safety
+/// `catalog` and `identifier` must be valid handles from previous paimon C
calls.
+#[no_mangle]
+pub unsafe extern "C" fn paimon_catalog_drop_table(
+ catalog: *const paimon_catalog,
+ identifier: *const paimon_identifier,
+ ignore_if_not_exists: bool,
+) -> *mut paimon_error {
+ if let Err(error) = check_non_null(catalog, "catalog") {
+ return error;
+ }
+ if let Err(error) = check_non_null(identifier, "identifier") {
+ return error;
+ }
+
+ let catalog = &*((*catalog).inner as *const Arc<dyn Catalog>);
+ let identifier = &*((*identifier).inner as *const Identifier);
+ match runtime().block_on(catalog.drop_table(identifier,
ignore_if_not_exists)) {
+ Ok(()) => std::ptr::null_mut(),
+ Err(error) => paimon_error::from_paimon(error),
+ }
+}
+
/// List the databases in a catalog.
///
/// On success `error` is null and `string_list` owns the database names; free
it
diff --git a/bindings/go/catalog.go b/bindings/go/catalog.go
index 1d82ec27..dfdd883c 100644
--- a/bindings/go/catalog.go
+++ b/bindings/go/catalog.go
@@ -113,6 +113,19 @@ func (c *Catalog) GetTable(id Identifier) (*Table, error) {
return &Table{ctx: c.ctx, lib: c.lib, inner: inner}, nil
}
+// DropTable drops a table. When ignoreIfNotExists is true, a missing table is
accepted.
+func (c *Catalog) DropTable(id Identifier, ignoreIfNotExists bool) error {
+ if c.inner == nil {
+ return ErrClosed
+ }
+ cID, err := c.newIdentifier(id)
+ if err != nil {
+ return err
+ }
+ defer ffiIdentifierFree.symbol(c.ctx)(cID)
+ return ffiCatalogDropTable.symbol(c.ctx)(c.inner, cID,
ignoreIfNotExists)
+}
+
func (c *Catalog) newIdentifier(id Identifier) (*paimonIdentifier, error) {
return ffiIdentifierNew.symbol(c.ctx)(id.database, id.object)
}
@@ -311,6 +324,22 @@ var ffiCatalogGetTable = newFFI(ffiOpts{
}
})
+var ffiCatalogDropTable = newFFI(ffiOpts{
+ sym: "paimon_catalog_drop_table",
+ rType: &ffi.TypePointer,
+ aTypes: []*ffi.Type{&ffi.TypePointer, &ffi.TypePointer, &ffi.TypeUint8},
+}, func(ctx context.Context, ffiCall ffiCall) func(*paimonCatalog,
*paimonIdentifier, bool) error {
+ return func(catalog *paimonCatalog, id *paimonIdentifier,
ignoreIfNotExists bool) error {
+ var ignore uint8
+ if ignoreIfNotExists {
+ ignore = 1
+ }
+ var ffiError *paimonError
+ ffiCall(unsafe.Pointer(&ffiError), unsafe.Pointer(&catalog),
unsafe.Pointer(&id), unsafe.Pointer(&ignore))
+ return parseError(ctx, ffiError)
+ }
+})
+
var ffiCatalogListDatabases = newFFI(ffiOpts{
sym: "paimon_catalog_list_databases",
rType: &typeResultStringList,
diff --git a/bindings/go/tests/catalog_drop_test.go
b/bindings/go/tests/catalog_drop_test.go
new file mode 100644
index 00000000..7caa4ecf
--- /dev/null
+++ b/bindings/go/tests/catalog_drop_test.go
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package paimon_test
+
+import (
+ "errors"
+ "path/filepath"
+ "slices"
+ "testing"
+
+ paimon "github.com/apache/paimon-rust/bindings/go"
+)
+
+func TestCatalogDropTable(t *testing.T) {
+ warehouse := t.TempDir()
+ const tableName = "map_blob_table"
+ if err := copyDirectory(filepath.Join("testdata", tableName),
filepath.Join(warehouse, "default.db", tableName)); err != nil {
+ t.Fatal(err)
+ }
+ catalog, err := paimon.NewCatalog(map[string]string{"warehouse":
warehouse})
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer catalog.Close()
+
+ id := paimon.NewIdentifier("default", tableName)
+ if err := catalog.DropTable(id, false); err != nil {
+ t.Fatal(err)
+ }
+ tables, err := catalog.ListTables("default")
+ if err != nil || slices.Contains(tables, tableName) {
+ t.Fatalf("ListTables = %v, %v; want %s absent", tables, err,
tableName)
+ }
+ var paimonErr *paimon.Error
+ if err := catalog.DropTable(id, false); !errors.As(err, &paimonErr) ||
paimonErr.Code() != paimon.CodeNotFound {
+ t.Fatalf("dropping a missing table returned %v; want
CodeNotFound", err)
+ }
+ if err := catalog.DropTable(id, true); err != nil {
+ t.Fatalf("ignoring a missing table returned %v", err)
+ }
+ catalog.Close()
+ if err := catalog.DropTable(id, false); !errors.Is(err,
paimon.ErrClosed) {
+ t.Fatalf("dropping with a closed catalog returned %v; want
ErrClosed", err)
+ }
+}
diff --git a/docs/src/go-binding.md b/docs/src/go-binding.md
index 698ac66b..ffa6c510 100644
--- a/docs/src/go-binding.md
+++ b/docs/src/go-binding.md
@@ -384,6 +384,12 @@ log.Printf("retained for %s", *tag.TagTimeRetained)
Pass `nil` for `timeRetained` to create a tag without retention metadata, the
same as `CreateTag`.
+## Dropping a Table
+
+Call `catalog.DropTable(id, ignoreIfNotExists)` to drop a table. Pass `true`
+for `DROP TABLE IF EXISTS` behavior. With `false`, a missing table returns
+a Paimon error with code `CodeNotFound`.
+
## Writing a Table
Use `NewWriteBuilder` for ordinary and fixed-bucket tables. The `arrow.Record`