-
Notifications
You must be signed in to change notification settings - Fork 67
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
Write fields.yml files for datasets #239
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type datasetContent struct { | ||
fields fieldsContent | ||
} | ||
|
||
type fieldsContent struct { | ||
files map[string][]byte | ||
} | ||
|
||
func createDatasets(modulePath string) (map[string]datasetContent, error) { | ||
datasetDirs, err := ioutil.ReadDir(modulePath) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "cannot module directory %s", modulePath) | ||
} | ||
|
||
contents := map[string]datasetContent{} | ||
for _, datasetDir := range datasetDirs { | ||
if !datasetDir.IsDir() { | ||
continue | ||
} | ||
datasetName := datasetDir.Name() | ||
|
||
if datasetName == "_meta" { | ||
continue | ||
} | ||
|
||
_, err := os.Stat(path.Join(modulePath, datasetName, "_meta")) | ||
if os.IsNotExist(err) { | ||
log.Printf("\t%s: not a valid dataset, skipped", datasetName) | ||
continue | ||
} | ||
|
||
log.Printf("\t%s: dataset found", datasetName) | ||
content := datasetContent{} | ||
|
||
fieldsFiles, err := loadDatasetFields(modulePath, datasetName) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "loading dataset fields failed (modulePath: %s, datasetName: %s)", | ||
modulePath, datasetName) | ||
} | ||
|
||
content.fields = fieldsContent{ | ||
files: map[string][]byte{ | ||
"fields.yml": fieldsFiles, | ||
}, | ||
} | ||
contents[datasetName] = content | ||
} | ||
return contents, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func loadDatasetFields(modulePath, datasetName string) ([]byte, error) { | ||
moduleFieldsPath := filepath.Join(modulePath, "_meta", "fields.yml") | ||
moduleFields, err := ioutil.ReadFile(moduleFieldsPath) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "reading module fields file failed (path: %s)", moduleFieldsPath) | ||
} | ||
|
||
var buffer bytes.Buffer | ||
buffer.Write(moduleFields) | ||
|
||
datasetFieldsPath := filepath.Join(modulePath, datasetName, "_meta", "fields.yml") | ||
datasetFieldsFile, err := os.Open(datasetFieldsPath) | ||
if os.IsNotExist(err) { | ||
log.Printf("Missing fields.yml file. Skipping. (path: %s)\n", datasetFieldsPath) | ||
return buffer.Bytes(), nil | ||
} else if err != nil { | ||
return nil, errors.Wrapf(err, "reading dataset fields file failed (path: %s)", moduleFieldsPath) | ||
} | ||
defer datasetFieldsFile.Close() | ||
|
||
scanner := bufio.NewScanner(datasetFieldsFile) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
buffer.Write([]byte(" ")) | ||
buffer.WriteString(line) | ||
buffer.WriteString("\n") | ||
} | ||
return buffer.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I would concatenate the fields.yml together. The package manager can support multiple
*.yml
files. Instead you could keep them separate but you need to add a top block to each dataset with the right "prefix". Keeping them separate has a few benefits I think:It could be argued, that the global fields should be on the package level but lets skip this for now as EPM does not support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any preferences regarding naming?
in every
module/dataset/foo/fields/
:package-fields.yml
fields.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference. The above LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll address this comment in #240