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

Function writeTMPFile

plugins/destination/duckdb/client/write.go:188–222  ·  view source on GitHub ↗
(table *schema.Table, msgs []*message.WriteInsert)

Source from the content-addressed store, hash-verified

186}
187
188func writeTMPFile(table *schema.Table, msgs []*message.WriteInsert) (fileName string, err error) {
189 sc := transformSchemaForWriting(table)
190
191 // create temp file
192 f, err := os.CreateTemp("", fmt.Sprintf("%s-*.parquet", table.Name))
193 if err != nil {
194 return "", err
195 }
196 defer f.Close() // we don't care here, as the happy-path will actually check the error
197 fileName = f.Name()
198
199 // prep file writer
200 fw, err := pqarrow.NewFileWriter(sc, f,
201 parquet.NewWriterProperties(
202 parquet.WithVersion(parquet.V2_LATEST), // use latest
203 parquet.WithMaxRowGroupLength(128*1024*1024), // 128M
204 // parquet.WithCompression(compress.Codecs.Snappy),
205 ),
206 pqarrow.NewArrowWriterProperties(pqarrow.WithStoreSchema()),
207 )
208 if err != nil {
209 return "", err
210 }
211 defer fw.Close() // we don't care here either as the happy path will check the error
212
213 // write records
214 for _, msg := range msgs {
215 if err = fw.WriteBuffered(transformRecord(sc, msg.Record)); err != nil {
216 return "", err
217 }
218 }
219
220 // close file writer (will close the underlying file, too)
221 return fileName, fw.Close()
222}
223
224func (c *Client) deleteInsert(ctx context.Context, tmpTableName string, table *schema.Table) error {
225 if err := c.deleteByPK(ctx, tmpTableName, table); err != nil {

Callers 1

WriteTableBatchMethod · 0.85

Calls 3

transformRecordFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected