Skip to content

Commit

Permalink
catalog: add Visit to VirtualSchemas
Browse files Browse the repository at this point in the history
This commit adds a new Visit method to the VirtualSchemas interface
which allows traversing the entirety of the virtual catalog.

Release note: None
  • Loading branch information
Marius Posta committed Dec 13, 2022
1 parent 5dd8946 commit 7939ba8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/sql/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type VirtualSchemas interface {
GetVirtualSchema(schemaName string) (VirtualSchema, bool)
GetVirtualSchemaByID(id descpb.ID) (VirtualSchema, bool)
GetVirtualObjectByID(id descpb.ID) (VirtualObject, bool)
Visit(func(desc Descriptor, comment string) error) error
}

// VirtualSchema represents a collection of VirtualObjects.
Expand Down
16 changes: 16 additions & 0 deletions pkg/sql/virtual_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/iterutil"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/errors"
)
Expand Down Expand Up @@ -397,6 +398,21 @@ func (vs *VirtualSchemaHolder) GetVirtualObjectByID(id descpb.ID) (catalog.Virtu
return entry, true
}

// Visit makes VirtualSchemaHolder implement catalog.VirtualSchemas.
func (vs *VirtualSchemaHolder) Visit(fn func(desc catalog.Descriptor, comment string) error) error {
for _, sc := range vs.schemasByID {
if err := fn(sc.desc, "" /* comment */); err != nil {
return iterutil.Map(err)
}
for _, def := range sc.defs {
if err := fn(def.desc, def.comment); err != nil {
return iterutil.Map(err)
}
}
}
return nil
}

var _ catalog.VirtualSchemas = (*VirtualSchemaHolder)(nil)

type virtualSchemaEntry struct {
Expand Down

0 comments on commit 7939ba8

Please sign in to comment.