github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/tablewriter_insert.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 // tableInserter handles writing kvs and forming table rows for inserts. 25 type tableInserter struct { 26 tableWriterBase 27 ri row.Inserter 28 } 29 30 var _ tableWriter = &tableInserter{} 31 32 // desc is part of the tableWriter interface. 33 func (*tableInserter) desc() string { return "inserter" } 34 35 // init is part of the tableWriter interface. 36 func (ti *tableInserter) init(_ context.Context, txn *kv.Txn, _ *tree.EvalContext) error { 37 ti.tableWriterBase.init(txn) 38 return nil 39 } 40 41 // row is part of the tableWriter interface. 42 func (ti *tableInserter) row( 43 ctx context.Context, values tree.Datums, ignoreIndexes util.FastIntSet, traceKV bool, 44 ) error { 45 ti.batchSize++ 46 return ti.ri.InsertRow(ctx, ti.b, values, ignoreIndexes, false /* overwrite */, row.CheckFKs, traceKV) 47 } 48 49 // atBatchEnd is part of the tableWriter interface. 50 func (ti *tableInserter) atBatchEnd(_ context.Context, _ bool) error { return nil } 51 52 // flushAndStartNewBatch is part of the tableWriter interface. 53 func (ti *tableInserter) flushAndStartNewBatch(ctx context.Context) error { 54 return ti.tableWriterBase.flushAndStartNewBatch(ctx, ti.tableDesc()) 55 } 56 57 // finalize is part of the tableWriter interface. 58 func (ti *tableInserter) finalize(ctx context.Context, _ bool) (*rowcontainer.RowContainer, error) { 59 return nil, ti.tableWriterBase.finalize(ctx, ti.tableDesc()) 60 } 61 62 // tableDesc is part of the tableWriter interface. 63 func (ti *tableInserter) tableDesc() *sqlbase.ImmutableTableDescriptor { 64 return ti.ri.Helper.TableDesc 65 } 66 67 // close is part of the tableWriter interface. 68 func (ti *tableInserter) close(_ context.Context) {} 69 70 // walkExprs is part of the tableWriter interface. 71 func (ti *tableInserter) walkExprs(_ func(desc string, index int, expr tree.TypedExpr)) {}