From 2b1482e39aa088408441a5a9cfcfc36e8d6e983c Mon Sep 17 00:00:00 2001 From: ajwerner Date: Mon, 27 Mar 2023 11:12:57 -0400 Subject: [PATCH] sql/catalog: add String and SafeFormat methods to DescriptorIDSet Epic: none Release note: None --- pkg/sql/catalog/BUILD.bazel | 1 + pkg/sql/catalog/descriptor_id_set.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/sql/catalog/BUILD.bazel b/pkg/sql/catalog/BUILD.bazel index 257de924276d..0e8c681059c8 100644 --- a/pkg/sql/catalog/BUILD.bazel +++ b/pkg/sql/catalog/BUILD.bazel @@ -46,6 +46,7 @@ go_library( "//pkg/util/iterutil", "@com_github_cockroachdb_errors//:errors", "@com_github_cockroachdb_redact//:redact", + "@com_github_cockroachdb_redact//interfaces", ], ) diff --git a/pkg/sql/catalog/descriptor_id_set.go b/pkg/sql/catalog/descriptor_id_set.go index 07eb0cac6198..ed56cc96fa48 100644 --- a/pkg/sql/catalog/descriptor_id_set.go +++ b/pkg/sql/catalog/descriptor_id_set.go @@ -13,6 +13,8 @@ package catalog import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/util/intsets" + "github.com/cockroachdb/redact" + "github.com/cockroachdb/redact/interfaces" ) // DescriptorIDSet efficiently stores an unordered set of descriptor ids. @@ -20,6 +22,16 @@ type DescriptorIDSet struct { set intsets.Fast } +// SafeFormat implements SafeFormatter for DescriptorIDSet. +func (d *DescriptorIDSet) SafeFormat(s interfaces.SafePrinter, verb rune) { + s.SafeString(redact.SafeString(d.String())) +} + +// String implement fmt.Stringer for DescriptorIDSet. +func (d *DescriptorIDSet) String() string { + return d.set.String() +} + // MakeDescriptorIDSet returns a set initialized with the given values. func MakeDescriptorIDSet(ids ...descpb.ID) DescriptorIDSet { s := DescriptorIDSet{} @@ -32,6 +44,8 @@ func MakeDescriptorIDSet(ids ...descpb.ID) DescriptorIDSet { // Suppress the linter. var _ = MakeDescriptorIDSet +var _ redact.SafeFormatter = (*DescriptorIDSet)(nil) + // Add adds an id to the set. No-op if the id is already in the set. func (d *DescriptorIDSet) Add(id descpb.ID) { d.set.Add(int(id))