zeroshade commented on code in PR #2691: URL: https://github.com/apache/iceberg-go/pull/2691#discussion_r4721971948
########## catalog/catalogtest/register_purge.go: ########## @@ -0,0 +1,146 @@ +// 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" + "testing" + + "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. +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") + } + + 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() + + 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") Review Comment: Nit: to back up "loads as the same table", also check `tbl.Metadata().TableUUID()` against the created table, the way `testRenameTable` does. ########## internal/recipe/setup-polaris.sh: ########## @@ -92,7 +92,8 @@ token=$(call -X POST "$api/catalog/v1/oauth/tokens" \ 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\"}, Review Comment: The grant block below has a comment explaining why it's there; please add one saying Polaris refuses `purgeRequested=true` without `drop-with-purge.enabled`. A note in `external_conformance_test.go` that the target server must allow purge would also help people running the suite against other servers. ########## catalog/catalogtest/register_purge.go: ########## @@ -0,0 +1,146 @@ +// 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" + "testing" + + "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. +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") Review Comment: For REST, `RegisterTable` returns `ErrEndpointNotSupported` (wrapping `iceberg.ErrNotImplemented`) when the server lists its endpoints without register. The external REST suite is meant to run against any server, so those servers would fail the three register cases instead of skipping. `newViewCatalog` handles the same case for views. A check here would fix it: call `RegisterTable` into a namespace that doesn't exist and `t.Skip` on `ErrNotImplemented`. That call fails on the client or gets a 404, so it changes nothing. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
