Skip to content

Commit

Permalink
fix(bigtable): Allow nil condition in conditional mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
bhshkh committed Jan 16, 2025
1 parent 0a81f8f commit af826d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ func (t *Table) apply(ctx context.Context, mt *builtinMetricsTracer, row string,
}

var callOptions []gax.CallOption
if m.cond == nil {
if !m.isConditional {
req := &btpb.MutateRowRequest{
AppProfileId: t.c.appProfile,
RowKey: []byte(row),
Expand All @@ -1065,9 +1065,11 @@ func (t *Table) apply(ctx context.Context, mt *builtinMetricsTracer, row string,
}

req := &btpb.CheckAndMutateRowRequest{
AppProfileId: t.c.appProfile,
RowKey: []byte(row),
PredicateFilter: m.cond.proto(),
AppProfileId: t.c.appProfile,
RowKey: []byte(row),
}
if m.cond != nil {
req.PredicateFilter = m.cond.proto()
}
if t.authorizedView == "" {
req.TableName = t.c.fullTableName(t.table)
Expand Down Expand Up @@ -1119,10 +1121,10 @@ func GetCondMutationResult(matched *bool) ApplyOption {

// Mutation represents a set of changes for a single row of a table.
type Mutation struct {
ops []*btpb.Mutation

ops []*btpb.Mutation
cond Filter
// for conditional mutations
cond Filter
isConditional bool
mtrue, mfalse *Mutation
}

Expand All @@ -1140,7 +1142,7 @@ func NewMutation() *Mutation {
// The application of a ReadModifyWrite is atomic; concurrent ReadModifyWrites will
// be executed serially by the server.
func NewCondMutation(cond Filter, mtrue, mfalse *Mutation) *Mutation {
return &Mutation{cond: cond, mtrue: mtrue, mfalse: mfalse}
return &Mutation{cond: cond, mtrue: mtrue, mfalse: mfalse, isConditional: true}
}

// Set sets a value in a specified column, with the given timestamp.
Expand Down Expand Up @@ -1248,7 +1250,7 @@ func (t *Table) ApplyBulk(ctx context.Context, rowKeys []string, muts []*Mutatio
origEntries := make([]*entryErr, len(rowKeys))
for i, key := range rowKeys {
mut := muts[i]
if mut.cond != nil {
if mut.isConditional {
return nil, errors.New("conditional mutations cannot be applied in bulk")
}
origEntries[i] = &entryErr{Entry: &btpb.MutateRowsRequest_Entry{RowKey: []byte(key), Mutations: mut.ops}}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/internal/testproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,9 @@ func (s *goTestProxyServer) CheckAndMutateRow(ctx context.Context, req *pb.Check
trueMuts := mutationFromProto(rrq.TrueMutations)
falseMuts := mutationFromProto(rrq.FalseMutations)

fmt.Printf("rrq: %+v\n", rrq)
rfPb := rrq.PredicateFilter
f := bigtable.PassAllFilter()
var f bigtable.Filter

if rfPb != nil {
f = *filterFromProto(rfPb)
Expand Down

0 comments on commit af826d7

Please sign in to comment.