MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / bulkInsert

Method bulkInsert

plugins/destination/mssql/client/bulk_insert.go:14–43  ·  view source on GitHub ↗
(ctx context.Context, tx *sql.Tx, table *schema.Table, records []arrow.RecordBatch)

Source from the content-addressed store, hash-verified

12)
13
14func (c *Client) bulkInsert(ctx context.Context, tx *sql.Tx, table *schema.Table, records []arrow.RecordBatch) error {
15 stmt, err := tx.PrepareContext(ctx,
16 mssql.CopyIn(queries.SanitizedTableName(c.spec.Schema, table),
17 mssql.BulkOptions{
18 KeepNulls: true,
19 KilobytesPerBatch: int(c.spec.BatchSizeBytes >> 10),
20 RowsPerBatch: int(c.spec.BatchSize),
21 Tablock: true,
22 },
23 table.Columns.Names()...,
24 ),
25 )
26 if err != nil {
27 return err
28 }
29
30 rows, err := queries.GetRows(array.NewTableFromRecords(table.ToArrowSchema(), records))
31 if err != nil {
32 return err
33 }
34 for _, row := range rows {
35 if _, err := stmt.ExecContext(ctx, row...); err != nil {
36 return err
37 }
38 }
39
40 // send bulkInsert
41 _, err = stmt.ExecContext(ctx)
42 return err
43}

Callers 1

WriteTableBatchMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected