| 12 | ) |
| 13 | |
| 14 | func (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 | } |