Skip to content

Commit

Permalink
fix: resolve vet failures
Browse files Browse the repository at this point in the history
Change-Id: Ie1e82d3a8389d26217f0fc10ffa9ca16f3b72b6d
  • Loading branch information
trollyxia committed Mar 13, 2024
1 parent dcff985 commit 4d35698
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
19 changes: 16 additions & 3 deletions bigtable/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ func (ac *AdminClient) UpdateBackup(ctx context.Context, cluster, backup string,
return err
}

// Authorized View APIs
// AuthorizedViewConf contains information about an authorized view.
type AuthorizedViewConf struct {
TableID string
AuthorizedViewID string
Expand All @@ -2194,16 +2194,20 @@ type AuthorizedViewConf struct {
DeletionProtection DeletionProtection
}

// AuthorizedViewTypeConf contains information about the type of an authorized view.
type AuthorizedViewTypeConf struct {
AuthorizedViewType AuthorizedViewType

SubsetView *SubsetViewConf
}

// AuthorizedViewType represents the type of an authorized view.
type AuthorizedViewType int

const (
// AuthorizedViewTypeUnspecified represents an unspecified authorized view type.
AuthorizedViewTypeUnspecified AuthorizedViewType = iota
// AuthorizedViewTypeSubsetView represents subset view type of an authorized view.
AuthorizedViewTypeSubsetView
)

Expand All @@ -2230,14 +2234,14 @@ func (av AuthorizedViewConf) proto() *btapb.AuthorizedView {
return &avp
}

// Sets the AuthorizedViewType to AuthorizedViewTypeSubsetView and the subsetView pointer accordingly
// SetSubsetView sets the AuthorizedViewType to AuthorizedViewTypeSubsetView and the subsetView pointer accordingly
func (av *AuthorizedViewTypeConf) SetSubsetView(s SubsetViewConf) error {
av.AuthorizedViewType = AuthorizedViewTypeSubsetView
av.SubsetView = &s
return nil
}

// Returns an error if the type is not AuthorizedViewTypeSubsetView.
// GetSubsetView returns an error if the type is not AuthorizedViewTypeSubsetView.
func (av *AuthorizedViewTypeConf) GetSubsetView() (*SubsetViewConf, error) {
if av.AuthorizedViewType != AuthorizedViewTypeSubsetView {
return nil, fmt.Errorf("not a subset view: :%v", av.AuthorizedViewType)
Expand All @@ -2250,11 +2254,13 @@ type familySubset struct {
QualifierPrefixes [][]byte
}

// SubsetViewConf contains configuration specific to an authorized view of subset view type.
type SubsetViewConf struct {
RowPrefixes [][]byte
FamilySubsets map[string]familySubset
}

// AddRowPrefix adds a new row prefix to the subset view.
func (s *SubsetViewConf) AddRowPrefix(prefix []byte) {
s.RowPrefixes = append(s.RowPrefixes, prefix)
}
Expand Down Expand Up @@ -2301,18 +2307,21 @@ func (s *SubsetViewConf) fillConf(internal *btapb.AuthorizedView_SubsetView) {
}
}

// AddFamilySubsetQualifier adds an individual column qualifier to be included in a subset view.
func (s *SubsetViewConf) AddFamilySubsetQualifier(familyName string, qualifier []byte) {
fs := s.getFamilySubset(familyName)
fs.Qualifiers = append(fs.Qualifiers, qualifier)
s.FamilySubsets[familyName] = fs
}

// AddFamilySubsetQualifier adds a prefix for column qualifiers to be included in a subset view.
func (s *SubsetViewConf) AddFamilySubsetQualifierPrefix(familyName string, qualifierPrefix []byte) {
fs := s.getFamilySubset(familyName)
fs.QualifierPrefixes = append(fs.QualifierPrefixes, qualifierPrefix)
s.FamilySubsets[familyName] = fs
}

// CreateAuthorizedView creates a new authorized view in a table.
func (ac *AdminClient) CreateAuthorizedView(ctx context.Context, conf *AuthorizedViewConf) error {
if conf.TableID == "" || conf.AuthorizedViewID == "" {
return errors.New("both AuthorizedViewID and TableID are required")
Expand All @@ -2331,6 +2340,7 @@ func (ac *AdminClient) CreateAuthorizedView(ctx context.Context, conf *Authorize
return err
}

// GetAuthorizedView retrieves information about an authorized view.
func (ac *AdminClient) GetAuthorizedView(ctx context.Context, tableID, authorizedViewID string) (*AuthorizedViewConf, error) {
ctx = mergeOutgoingMetadata(ctx, ac.md)
req := &btapb.GetAuthorizedViewRequest{
Expand Down Expand Up @@ -2387,11 +2397,13 @@ func (ac *AdminClient) AuthorizedViews(ctx context.Context, tableID string) ([]s
return names, nil
}

// UpdateAuthorizedViewConf contains all the information necessary to update or partial update an authorized view.
type UpdateAuthorizedViewConf struct {
AuthorizedViewConf AuthorizedViewConf
UpdateMask []string
}

// UpdateAuthorizedView updates an authorized view in a table according to the given configuration.
func (ac *AdminClient) UpdateAuthorizedView(ctx context.Context, conf UpdateAuthorizedViewConf) error {
ctx = mergeOutgoingMetadata(ctx, ac.md)
if conf.AuthorizedViewConf.TableID == "" || conf.AuthorizedViewConf.AuthorizedViewID == "" {
Expand All @@ -2415,6 +2427,7 @@ func (ac *AdminClient) UpdateAuthorizedView(ctx context.Context, conf UpdateAuth
return nil
}

// DeleteAuthorizedView deletes an authorized view in a table.
func (ac *AdminClient) DeleteAuthorizedView(ctx context.Context, tableID, authorizedViewID string) error {
ctx = mergeOutgoingMetadata(ctx, ac.md)
req := &btapb.DeleteAuthorizedViewRequest{
Expand Down
9 changes: 6 additions & 3 deletions bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func mergeOutgoingMetadata(ctx context.Context, mds ...metadata.MD) context.Cont
return metadata.NewOutgoingContext(ctx, metadata.Join(allMDs...))
}

type TableApi interface {
// TableAPI interface allows existing data APIs to be applied to either an authorized view or a table.
type TableAPI interface {
ReadRows(ctx context.Context, arg RowSet, f func(Row) bool, opts ...ReadOption) error
ReadRow(ctx context.Context, row string, opts ...ReadOption) (Row, error)
Apply(ctx context.Context, row string, m *Mutation, opts ...ApplyOption) error
Expand Down Expand Up @@ -186,7 +187,8 @@ func (c *Client) Open(table string) *Table {
}
}

func (c *Client) OpenTable(table string) TableApi {
// OpenTable opens a table.
func (c *Client) OpenTable(table string) TableAPI {
return &tableImpl{Table{
c: c,
table: table,
Expand All @@ -197,7 +199,8 @@ func (c *Client) OpenTable(table string) TableApi {
}}
}

func (c *Client) OpenAuthorizedView(table, authorizedView string) TableApi {
// OpenAuthorizedView opens an authorized view.
func (c *Client) OpenAuthorizedView(table, authorizedView string) TableAPI {
return &tableImpl{Table{
c: c,
table: table,
Expand Down

0 comments on commit 4d35698

Please sign in to comment.