mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-10 04:47:53 +00:00
create frames with input-definition's creation
This commit is contained in:
parent
a62ec47eec
commit
1c2adda8e9
3 changed files with 21 additions and 21 deletions
22
handler.go
22
handler.go
|
|
@ -1507,10 +1507,7 @@ func (h *Handler) handlePostDefinition(w http.ResponseWriter, r *http.Request) {
|
|||
// Decode request.
|
||||
var req postInputDefinition
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err == io.EOF {
|
||||
// If no data was provided (EOF), we still create the frame
|
||||
// with default values.
|
||||
} else if err != nil {
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
@ -1532,15 +1529,14 @@ func (h *Handler) handlePostDefinition(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
//err = h.Broadcaster.SendSync(
|
||||
// &internal.CreateInputDefinitionMessage{
|
||||
// Index: indexName,
|
||||
// InputDefinition: inputDefName,
|
||||
// Meta: req.Options.Encode(),
|
||||
// })
|
||||
//if err != nil {
|
||||
// h.logger().Printf("problem sending CreateFrame message: %s", err)
|
||||
//}
|
||||
err = h.Broadcaster.SendSync(
|
||||
&internal.CreateInputDefinitionMessage{
|
||||
Index: indexName,
|
||||
InputDefinition: inputDefName,
|
||||
})
|
||||
if err != nil {
|
||||
h.logger().Printf("problem sending CreateInputDefinition message: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) handleGetDefinition(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
17
index.go
17
index.go
|
|
@ -414,8 +414,6 @@ func (i *Index) CreateFrame(name string, opt FrameOptions) (*Frame, error) {
|
|||
|
||||
// CreateInputDefinition creates a new input definition.
|
||||
func (i *Index) CreateInputDefinition(name string, frames []InputFrame, field []Field) (*InputDefinition, error) {
|
||||
i.mu.Lock()
|
||||
defer i.mu.Unlock()
|
||||
|
||||
// Ensure input definition doesn't already exist.
|
||||
if i.inputDefinitions[name] != nil {
|
||||
|
|
@ -431,16 +429,20 @@ func (i *Index) createInputDefinition(name string, frames []InputFrame, fields [
|
|||
return nil, errors.New("frames and fields are required")
|
||||
}
|
||||
|
||||
for _, fr := range frames {
|
||||
_, err := i.CreateFrame(fr.Name, fr.Options)
|
||||
if err == ErrFrameExists {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize input definition.
|
||||
inputDef, err := i.newInputDefinition(i.InputDefPath(), name)
|
||||
fmt.Println(inputDef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Open input definition.
|
||||
if err := inputDef.Open(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
inputDef.frames = frames
|
||||
inputDef.fields = fields
|
||||
|
|
@ -448,7 +450,6 @@ func (i *Index) createInputDefinition(name string, frames []InputFrame, fields [
|
|||
return nil, err
|
||||
}
|
||||
i.inputDefinitions[name] = inputDef
|
||||
fmt.Printf("%+v\n", i.inputDefinitions[name])
|
||||
return inputDef, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,9 @@ func (i *InputDefinition) loadMeta() error {
|
|||
|
||||
//saveMeta writes meta data for the input definition file.
|
||||
func (i *InputDefinition) saveMeta() error {
|
||||
if err := os.MkdirAll(i.path, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
// Marshal metadata.
|
||||
var frames []*internal.Frame
|
||||
for _, fr := range i.frames {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue