Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bindings/c/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions bindings/go/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
62 changes: 62 additions & 0 deletions bindings/go/tests/catalog_drop_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
6 changes: 6 additions & 0 deletions docs/src/go-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Loading