Skip to content

Commit

Permalink
Add CSV file import function (#27149)
Browse files Browse the repository at this point in the history
Signed-off-by: kuma <[email protected]>
Co-authored-by: kuma <[email protected]>
  • Loading branch information
KumaJie and kuma authored Oct 31, 2023
1 parent 0677d26 commit e88212b
Show file tree
Hide file tree
Showing 10 changed files with 2,115 additions and 13 deletions.
10 changes: 5 additions & 5 deletions internal/rootcoord/import_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,18 +399,18 @@ func (m *importManager) isRowbased(files []string) (bool, error) {
isRowBased := false
for _, filePath := range files {
_, fileType := importutil.GetFileNameAndExt(filePath)
if fileType == importutil.JSONFileExt {
if fileType == importutil.JSONFileExt || fileType == importutil.CSVFileExt {
isRowBased = true
} else if isRowBased {
log.Error("row-based data file type must be JSON, mixed file types is not allowed", zap.Strings("files", files))
return isRowBased, fmt.Errorf("row-based data file type must be JSON, file type '%s' is not allowed", fileType)
log.Error("row-based data file type must be JSON or CSV, mixed file types is not allowed", zap.Strings("files", files))
return isRowBased, fmt.Errorf("row-based data file type must be JSON or CSV, file type '%s' is not allowed", fileType)
}
}

// for row_based, we only allow one file so that each invocation only generate a task
if isRowBased && len(files) > 1 {
log.Error("row-based import, only allow one JSON file each time", zap.Strings("files", files))
return isRowBased, fmt.Errorf("row-based import, only allow one JSON file each time")
log.Error("row-based import, only allow one JSON or CSV file each time", zap.Strings("files", files))
return isRowBased, fmt.Errorf("row-based import, only allow one JSON or CSV file each time")
}

return isRowBased, nil
Expand Down
20 changes: 20 additions & 0 deletions internal/rootcoord/import_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,26 @@ func TestImportManager_isRowbased(t *testing.T) {
rb, err = mgr.isRowbased(files)
assert.NoError(t, err)
assert.False(t, rb)

files = []string{"1.csv"}
rb, err = mgr.isRowbased(files)
assert.NoError(t, err)
assert.True(t, rb)

files = []string{"1.csv", "2.csv"}
rb, err = mgr.isRowbased(files)
assert.Error(t, err)
assert.True(t, rb)

files = []string{"1.csv", "2.json"}
rb, err = mgr.isRowbased(files)
assert.Error(t, err)
assert.True(t, rb)

files = []string{"1.csv", "2.npy"}
rb, err = mgr.isRowbased(files)
assert.Error(t, err)
assert.True(t, rb)
}

func TestImportManager_mergeArray(t *testing.T) {
Expand Down
Loading

0 comments on commit e88212b

Please sign in to comment.