This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 244f12b2f test(catalogtest): cover RegisterTable and PurgeTable (#2691)
244f12b2f is described below
commit 244f12b2f3cf06410578dc096144dff583ab6c9a
Author: Andrei Tserakhau <[email protected]>
AuthorDate: Fri Nov 27 22:57:25 2026 +0100
test(catalogtest): cover RegisterTable and PurgeTable (#2691)
The conformance suite never called RegisterTable or PurgeTable, so a
catalog could return the wrong sentinel for either and CI would not
notice.
Add five cases in catalog/catalogtest/register_purge.go, following
Java's CatalogTests:
- a table dropped without purge can be registered again from its
metadata file and loads with the same identifier, metadata location
and schema;
- registering over an existing table fails with ErrTableAlreadyExists;
- registering into a missing namespace fails with ErrNoSuchNamespace;
- a purged table is gone and LoadTable fails with ErrNoSuchTable;
- purging a missing table fails with ErrNoSuchTable.
The register cases find catalog.RegisterableCatalog with catalog.As and
skip when the catalog does not implement it, so they run on REST, Hive
and DynamoDB and skip on SQL and Hadoop. The purge cases run on every
wired catalog. File removal is not checked, since PurgeTable deletes
files on a best-effort basis.
---
catalog/catalogtest/catalogtest.go | 5 +
catalog/catalogtest/register_purge.go | 157 ++++++++++++++++++++++++++++++
catalog/rest/external_conformance_test.go | 3 +-
internal/recipe/setup-polaris.sh | 5 +-
4 files changed, 168 insertions(+), 2 deletions(-)
diff --git a/catalog/catalogtest/catalogtest.go
b/catalog/catalogtest/catalogtest.go
index 74092b3cb..1968dfcaf 100644
--- a/catalog/catalogtest/catalogtest.go
+++ b/catalog/catalogtest/catalogtest.go
@@ -133,6 +133,11 @@ func RunCatalogTests(t *testing.T, cfg Config) {
} else {
t.Run("RenameTableNotSupported", func(t *testing.T) {
testRenameTableNotSupported(t, cfg) })
}
+ t.Run("RegisterTable", func(t *testing.T) { testRegisterTable(t, cfg) })
+ t.Run("RegisterExistingTable", func(t *testing.T) {
testRegisterExistingTable(t, cfg) })
+ t.Run("RegisterTableInMissingNamespace", func(t *testing.T) {
testRegisterTableInMissingNamespace(t, cfg) })
+ t.Run("PurgeTable", func(t *testing.T) { testPurgeTable(t, cfg) })
+ t.Run("PurgeMissingTable", func(t *testing.T) {
testPurgeMissingTable(t, cfg) })
t.Run("CreateTableWithProperties", func(t *testing.T) {
testCreateTableWithProperties(t, cfg) })
t.Run("UpdateTableProperties", func(t *testing.T) {
testUpdateTableProperties(t, cfg) })
diff --git a/catalog/catalogtest/register_purge.go
b/catalog/catalogtest/register_purge.go
new file mode 100644
index 000000000..a377de722
--- /dev/null
+++ b/catalog/catalogtest/register_purge.go
@@ -0,0 +1,157 @@
+// 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 catalogtest
+
+import (
+ "context"
+ "errors"
+ "testing"
+
+ "github.com/apache/iceberg-go"
+ "github.com/apache/iceberg-go/catalog"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+// newRegisterableCatalog returns a fresh catalog from cfg and its register
+// capability. It skips the test when the catalog cannot register tables, as
+// the SQL and Hadoop catalogs cannot, or when it reports register as not
+// implemented, as a REST server that does not advertise the endpoint does.
+func newRegisterableCatalog(t *testing.T, cfg Config) (catalog.Catalog,
catalog.RegisterableCatalog) {
+ t.Helper()
+
+ cat := cfg.NewCatalog(t)
+ registerable, ok := catalog.As[catalog.RegisterableCatalog](cat)
+ if !ok {
+ t.Skip("catalog does not implement catalog.RegisterableCatalog")
+ }
+
+ // The namespace does not exist, so this registers nothing.
+ _, ident := newIdentifiers()
+ if _, err := registerable.RegisterTable(context.Background(), ident,
"missing.metadata.json"); errors.Is(err, iceberg.ErrNotImplemented) {
+ t.Skipf("catalog does not support register: %v", err)
+ }
+
+ return cat, registerable
+}
+
+// testRegisterTable asserts that a table dropped without purge can be
+// registered again from its metadata file and loads as the same table.
+func testRegisterTable(t *testing.T, cfg Config) {
+ ctx := context.Background()
+ cat, registerable := newRegisterableCatalog(t, cfg)
+ namespace, ident := newIdentifiers()
+
+ require.NoError(t, cat.CreateNamespace(ctx, namespace, nil))
+ t.Cleanup(func() { _ = cat.DropNamespace(ctx, namespace) })
+
+ created, err := cat.CreateTable(ctx, ident, Schema)
+ require.NoError(t, err)
+ metadataLocation := created.MetadataLocation()
+ originalUUID := created.Metadata().TableUUID()
+
+ require.NoError(t, cat.DropTable(ctx, ident))
+
+ _, err = registerable.RegisterTable(ctx, ident, metadataLocation)
+ require.NoError(t, err)
+ t.Cleanup(func() { _ = cat.DropTable(ctx, ident) })
+
+ exists, err := cat.CheckTableExists(ctx, ident)
+ require.NoError(t, err)
+ assert.True(t, exists, "table should exist after register")
+
+ tbl, err := cat.LoadTable(ctx, ident)
+ require.NoError(t, err)
+ assert.Equal(t, ident, tbl.Identifier(), "registered table should
report the identifier it was registered under")
+ assert.Equal(t, metadataLocation, tbl.MetadataLocation(), "registered
table should point at the registered metadata file")
+ assert.Equal(t, TableSchema.AsStruct(), tbl.Schema().AsStruct(),
"registered table should keep its schema")
+ assert.Equal(t, originalUUID, tbl.Metadata().TableUUID(), "registered
table should keep its identity")
+}
+
+// testRegisterExistingTable asserts that registering over an existing table is
+// rejected.
+func testRegisterExistingTable(t *testing.T, cfg Config) {
+ ctx := context.Background()
+ cat, registerable := newRegisterableCatalog(t, cfg)
+ namespace, ident := newIdentifiers()
+
+ require.NoError(t, cat.CreateNamespace(ctx, namespace, nil))
+ t.Cleanup(func() { _ = cat.DropNamespace(ctx, namespace) })
+
+ created, err := cat.CreateTable(ctx, ident, Schema)
+ require.NoError(t, err)
+ t.Cleanup(func() { _ = cat.DropTable(ctx, ident) })
+
+ _, err = registerable.RegisterTable(ctx, ident,
created.MetadataLocation())
+ assert.ErrorIs(t, err, catalog.ErrTableAlreadyExists)
+}
+
+// testRegisterTableInMissingNamespace asserts that registering into a
+// namespace that does not exist reports the missing namespace.
+func testRegisterTableInMissingNamespace(t *testing.T, cfg Config) {
+ ctx := context.Background()
+ cat, registerable := newRegisterableCatalog(t, cfg)
+ namespace, ident := newIdentifiers()
+ _, missing := newIdentifiers()
+
+ require.NoError(t, cat.CreateNamespace(ctx, namespace, nil))
+ t.Cleanup(func() { _ = cat.DropNamespace(ctx, namespace) })
+
+ created, err := cat.CreateTable(ctx, ident, Schema)
+ require.NoError(t, err)
+ t.Cleanup(func() { _ = cat.DropTable(ctx, ident) })
+
+ _, err = registerable.RegisterTable(ctx, missing,
created.MetadataLocation())
+ assert.ErrorIs(t, err, catalog.ErrNoSuchNamespace)
+}
+
+// testPurgeTable asserts that a purged table is no longer visible. Whether its
+// files are removed is not checked, since the contract makes that best-effort.
+func testPurgeTable(t *testing.T, cfg Config) {
+ ctx := context.Background()
+ cat := cfg.NewCatalog(t)
+ namespace, ident := newIdentifiers()
+
+ require.NoError(t, cat.CreateNamespace(ctx, namespace, nil))
+ t.Cleanup(func() { _ = cat.DropNamespace(ctx, namespace) })
+
+ _, err := cat.CreateTable(ctx, ident, Schema)
+ require.NoError(t, err)
+
+ require.NoError(t, cat.PurgeTable(ctx, ident))
+
+ exists, err := cat.CheckTableExists(ctx, ident)
+ require.NoError(t, err)
+ assert.False(t, exists, "table should not exist after purge")
+
+ _, err = cat.LoadTable(ctx, ident)
+ assert.ErrorIs(t, err, catalog.ErrNoSuchTable)
+}
+
+// testPurgeMissingTable asserts that purging a table that was never created
+// reports that the table does not exist.
+func testPurgeMissingTable(t *testing.T, cfg Config) {
+ ctx := context.Background()
+ cat := cfg.NewCatalog(t)
+ namespace, ident := newIdentifiers()
+
+ require.NoError(t, cat.CreateNamespace(ctx, namespace, nil))
+ t.Cleanup(func() { _ = cat.DropNamespace(ctx, namespace) })
+
+ assert.ErrorIs(t, cat.PurgeTable(ctx, ident), catalog.ErrNoSuchTable)
+}
diff --git a/catalog/rest/external_conformance_test.go
b/catalog/rest/external_conformance_test.go
index 36d070ae7..b4585aa8d 100644
--- a/catalog/rest/external_conformance_test.go
+++ b/catalog/rest/external_conformance_test.go
@@ -57,7 +57,8 @@ const (
// TestExternalRestCatalogConformance runs the catalog conformance suite
against
// an external REST catalog server. It is opt-in: the test is skipped unless
-// REST_CATALOG_URI is set.
+// REST_CATALOG_URI is set. The server must allow purging tables on drop, which
+// Polaris, for example, only does with drop-with-purge.enabled.
func TestExternalRestCatalogConformance(t *testing.T) {
uri := os.Getenv(externalURIEnv)
if uri == "" {
diff --git a/internal/recipe/setup-polaris.sh b/internal/recipe/setup-polaris.sh
index 1da88be3e..0c9ebabee 100755
--- a/internal/recipe/setup-polaris.sh
+++ b/internal/recipe/setup-polaris.sh
@@ -89,10 +89,13 @@ token=$(call -X POST "$api/catalog/v1/oauth/tokens" \
-d client_secret="$client_secret" -d scope=PRINCIPAL_ROLE:ALL |
jq -er .access_token)
+# Polaris rejects purgeRequested=true unless drop-with-purge.enabled is set,
+# which the PurgeTable conformance tests need.
call -X POST "$api/management/v1/catalogs" \
-H "Authorization: Bearer $token" -H 'Content-Type: application/json' \
-d "{\"catalog\":{\"name\":\"$warehouse\",\"type\":\"INTERNAL\",
- \"properties\":{\"default-base-location\":\"$location\"},
+ \"properties\":{\"default-base-location\":\"$location\",
+ \"polaris.config.drop-with-purge.enabled\":\"true\"},
\"storageConfigInfo\":{\"storageType\":\"FILE\",\"allowedLocations\":[\"$location\"]}}}"
\
> /dev/null