github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/tablewriter_update.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sql 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/kv" 17 "github.com/cockroachdb/cockroach/pkg/sql/row" 18 "github.com/cockroachdb/cockroach/pkg/sql/rowcontainer" 19 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 20 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 21 "github.com/cockroachdb/cockroach/pkg/util" 22 ) 23 24 // tableUpdater handles writing kvs and forming table rows for updates. 25 type tableUpdater struct { 26 tableWriterBase 27 ru row.Updater 28 } 29 30 var _ tableWriter = &tableUpdater{} 31 32 // desc is part of the tableWriter interface. 33 func (*tableUpdater) desc() string { return "updater" } 34 35 // init is part of the tableWriter interface. 36 func (tu *tableUpdater) init(_ context.Context, txn *kv.Txn, _ *tree.EvalContext) error { 37 tu.tableWriterBase.init(txn) 38 return nil 39 } 40 41 // row is part of the tableWriter interface. 42 // We don't implement this because tu.ru.UpdateRow wants two slices 43 // and it would be a shame to split the incoming slice on every call. 44 // Instead provide a separate rowForUpdate() below. 45 func (tu *tableUpdater) row(context.Context, tree.Datums, util.FastIntSet, bool) error { 46 panic("unimplemented") 47 } 48 49 // rowForUpdate extends row() from the tableWriter interface. 50 func (tu *tableUpdater) rowForUpdate( 51 ctx context.Context, oldValues, updateValues tree.Datums, traceKV bool, 52 ) (tree.Datums, error) { 53 tu.batchSize++ 54 return tu.ru.UpdateRow(ctx, tu.b, oldValues, updateValues, row.CheckFKs, traceKV) 55 } 56 57 // atBatchEnd is part of the tableWriter interface. 58 func (tu *tableUpdater) atBatchEnd(_ context.Context, _ bool) error { return nil } 59 60 // flushAndStartNewBatch is part of the tableWriter interface. 61 func (tu *tableUpdater) flushAndStartNewBatch(ctx context.Context) error { 62 return tu.tableWriterBase.flushAndStartNewBatch(ctx, tu.tableDesc()) 63 } 64 65 // finalize is part of the tableWriter interface. 66 func (tu *tableUpdater) finalize(ctx context.Context, _ bool) (*rowcontainer.RowContainer, error) { 67 return nil, tu.tableWriterBase.finalize(ctx, tu.tableDesc()) 68 } 69 70 // tableDesc is part of the tableWriter interface. 71 func (tu *tableUpdater) tableDesc() *sqlbase.ImmutableTableDescriptor { 72 return tu.ru.Helper.TableDesc 73 } 74 75 // close is part of the tableWriter interface. 76 func (tu *tableUpdater) close(_ context.Context) {} 77 78 // walkExprs is part of the tableWriter interface. 79 func (tu *tableUpdater) walkExprs(_ func(desc string, index int, expr tree.TypedExpr)) {}