Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for wildcard filename #153

Merged
merged 7 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/v2/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ files:
- name: likeness
type: double

- path: ./glob-follow-*.csv
failDataPath: ./err/follow-glob.csv
batchSize: 2
type: csv
csv:
withHeader: false
withLabel: false
schema:
type: edge
edge:
name: follow
withRanking: true
props:
- name: likeness
type: double


- path: ./follow-with-header.csv
failDataPath: ./err/follow-with-header.csv
batchSize: 2
Expand Down
3 changes: 3 additions & 0 deletions examples/v2/glob-follow-1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x200,y201,0,92.5
y201,x200,1,85.6
y201,z202,2,93.2
1 change: 1 addition & 0 deletions examples/v2/glob-follow-2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
y201,z202,1,96.2
50 changes: 50 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func (config *YAMLConfig) ValidateAndReset(dir string) error {
return errors.New("There is no files in configuration")
}

//TODO(yuyu): check each item in config.Files
// if item is a directory, iter this directory and replace this directory config section by filename config section
if err := config.expandDirectoryToFiles(dir); err != nil {
logger.Errorf("%s", err)
IanSmith123 marked this conversation as resolved.
Show resolved Hide resolved
return err
}
for i := range config.Files {
if err := config.Files[i].validateAndReset(dir, fmt.Sprintf("files[%d]", i)); err != nil {
return err
Expand All @@ -192,6 +198,24 @@ func (config *YAMLConfig) ValidateAndReset(dir string) error {
return nil
}

func (config *YAMLConfig) expandDirectoryToFiles(dir string) (err error) {
var newFiles []*File

for _, file := range config.Files {
err, files := file.expandFiles(dir)
if err != nil {
logger.Errorf("error when expand file: %s", err)
return err
}
for _, f := range files {
newFiles = append(newFiles, f)
}
}
config.Files = newFiles

return err
}

func (n *NebulaPostStart) validateAndReset(prefix string) error {
if n.AfterPeriod != nil {
_, err := time.ParseDuration(*n.AfterPeriod)
Expand Down Expand Up @@ -334,6 +358,32 @@ func (f *File) validateAndReset(dir, prefix string) error {
return f.Schema.validateAndReset(fmt.Sprintf("%s.schema", prefix))
}

func (f *File) expandFiles(dir string) (err error, files []*File) {
if base.HasHttpPrefix(*f.Path) {
files = append(files, f)
} else {
if !filepath.IsAbs(*f.Path) {
absPath := filepath.Join(dir, *f.Path)
f.Path = &absPath
}

fileNames, err := filepath.Glob(*f.Path)
if err != nil || len(fileNames) == 0 {
logger.Errorf("error file path: %s", *f.Path)
return err, files
}

for _, name := range fileNames {
eachConf := f
eachConf.Path = &name
files = append(files, eachConf)
logger.Infof("find file: %v", *f.Path)
}
}

return err, files
}

func (c *CSVConfig) validateAndReset(prefix string) error {
if c.WithHeader == nil {
h := false
Expand Down