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
13 changes: 13 additions & 0 deletions catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ func validateIdentifier(ident table.Identifier, notFoundErr error) error {
notFoundErr, strings.Join(ident, "."))
}

return validateIdentifierComponents(ident, notFoundErr)
}

func validateIdentifierComponents(ident table.Identifier, notFoundErr error) error {
for _, part := range ident {
if part == "" || part == "." || part == ".." || strings.Contains(part, "/") {
return fmt.Errorf("%w: invalid identifier component %q in %v",
Expand All @@ -272,6 +276,15 @@ func validateIdentifier(ident table.Identifier, notFoundErr error) error {
return nil
}

// ValidateNamespaceIdentifier checks that an identifier contains at least one valid namespace level.
func ValidateNamespaceIdentifier(ident table.Identifier) error {
if len(ident) < 1 {
return fmt.Errorf("%w: empty namespace identifier", ErrNoSuchNamespace)
}

return validateIdentifierComponents(ident, ErrNoSuchNamespace)
}

// ValidateTableIdentifier checks that an identifier contains at least one valid namespace level and a table name.
func ValidateTableIdentifier(ident table.Identifier) error {
return validateIdentifier(ident, ErrNoSuchTable)
Expand Down
18 changes: 18 additions & 0 deletions catalog/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ func TestValidateTableIdentifier(t *testing.T) {
}
}

func TestValidateNamespaceIdentifier(t *testing.T) {
require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"namespace"}))
require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"parent", "namespace"}))

for _, ident := range []table.Identifier{
nil,
{},
{""},
{"."},
{".."},
{"namespace/child"},
{"namespace\nchild"},
{"parent", ""},
} {
require.ErrorIs(t, catalog.ValidateNamespaceIdentifier(ident), catalog.ErrNoSuchNamespace)
}
}

func TestNamespaceFromEmptyIdentifier(t *testing.T) {
require.Nil(t, catalog.NamespaceFromIdent(nil))
require.Nil(t, catalog.NamespaceFromIdent(table.Identifier{}))
Expand Down
6 changes: 1 addition & 5 deletions catalog/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,7 @@ func (r *Catalog) Close() error { return r.reporter.Close() }
var _ catalog.Closer = (*Catalog)(nil)

func checkValidNamespace(ident table.Identifier) error {
if len(ident) < 1 {
return fmt.Errorf("%w: empty namespace identifier", catalog.ErrNoSuchNamespace)
}

return nil
return catalog.ValidateNamespaceIdentifier(ident)
}

func (r *Catalog) tableFromResponse(_ context.Context, identifier []string, metadata table.Metadata, loc string, config iceberg.Properties, credsVended bool) (*table.Table, error) {
Expand Down
Loading