MCPcopy
hub / github.com/apache/devlake / UpdateCSVs

Method UpdateCSVs

backend/helpers/e2ehelper/data_flow_tester.go:259–305  ·  view source on GitHub ↗

UpdateCSVs scans the supplied directory for .csv files and applies the `updater` function to each. It saves back the result. This is useful when you need to bulk-change a lot of entries across many CSV files in a systematic way.

(csvDir string, updater func(fileName string, record *pluginhelper.CsvRecord))

Source from the content-addressed store, hash-verified

257// UpdateCSVs scans the supplied directory for .csv files and applies the `updater` function to each. It saves back the result.
258// This is useful when you need to bulk-change a lot of entries across many CSV files in a systematic way.
259func (t *DataFlowTester) UpdateCSVs(csvDir string, updater func(fileName string, record *pluginhelper.CsvRecord)) errors.Error {
260 var csvFiles []string
261 err := filepath.WalkDir(csvDir, func(file string, dir fs.DirEntry, e error) error {
262 if e != nil {
263 return e
264 }
265 if filepath.Ext(file) == ".csv" {
266 csvFiles = append(csvFiles, file)
267 }
268 return nil
269 })
270 if err != nil {
271 return errors.Convert(err)
272 }
273 for _, csvFile := range csvFiles {
274 csvIter, err := pluginhelper.NewCsvFileIterator(csvFile)
275 if err != nil {
276 return errors.Convert(err)
277 }
278 columns := csvIter.GetColumns()
279 var entries [][]string
280 func() {
281 defer csvIter.Close()
282 for csvIter.HasNext() {
283 records := csvIter.FetchRecords()
284 var csvEntry []string
285 for _, record := range records {
286 updater(filepath.Base(csvFile), record)
287 csvEntry = append(csvEntry, cast.ToString(record.Value))
288 }
289 entries = append(entries, csvEntry)
290 }
291 }()
292 if len(entries) == 0 {
293 continue
294 }
295 func() {
296 csvWriter, _ := pluginhelper.NewCsvFileWriter(csvFile, columns)
297 defer csvWriter.Close()
298 for _, entry := range entries {
299 csvWriter.Write(entry)
300 }
301 csvWriter.Flush()
302 }()
303 }
304 return nil
305}
306
307// CreateSnapshot reads rows from database and write them into .csv file.
308func (t *DataFlowTester) CreateSnapshot(dst schema.Tabler, opts TableOptions) {

Callers

nothing calls this directly

Calls 8

GetColumnsMethod · 0.95
CloseMethod · 0.95
HasNextMethod · 0.95
FetchRecordsMethod · 0.95
CloseMethod · 0.95
WriteMethod · 0.95
FlushMethod · 0.95
ConvertMethod · 0.45

Tested by

no test coverage detected