adjusted some of the InputDefinition comments

This commit is contained in:
Travis 2017-06-26 17:39:58 -05:00
parent 53c7e5946d
commit 904552b289
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
4 changed files with 35 additions and 35 deletions

View file

@ -1499,11 +1499,18 @@ func errorString(err error) string {
return err.Error()
}
// handlePOSTInputDefinition handles POST /input-definition request.
// handlePostInputDefinition handles POST /input-definition request.
func (h *Handler) handlePostInputDefinition(w http.ResponseWriter, r *http.Request) {
indexName := mux.Vars(r)["index"]
inputDefName := mux.Vars(r)["input-definition"]
// Find index.
index := h.Holder.Index(indexName)
if index == nil {
http.Error(w, ErrIndexNotFound.Error(), http.StatusNotFound)
return
}
// Decode request.
var req InputDefinitionInfo
err := json.NewDecoder(r.Body).Decode(&req)
@ -1512,13 +1519,7 @@ func (h *Handler) handlePostInputDefinition(w http.ResponseWriter, r *http.Reque
return
}
// Find index.
index := h.Holder.Index(indexName)
if index == nil {
http.Error(w, ErrIndexNotFound.Error(), http.StatusNotFound)
return
}
// Encode InputDefinition to its internal representation.
def, err := req.Encode()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@ -1526,22 +1527,20 @@ func (h *Handler) handlePostInputDefinition(w http.ResponseWriter, r *http.Reque
}
def.Name = inputDefName
// Validate columnLabel & duplicate primaryKey
// Validate columnLabel and duplicate primaryKey.
numPrimaryKey := 0
for _, field := range def.Fields {
if field.PrimaryKey {
numPrimaryKey += 1
if field.Name == index.columnLabel {
continue
} else {
err = fmt.Errorf("primary field's name not match columnLabel")
if field.Name != index.columnLabel {
err = fmt.Errorf("PrimaryKey field name does not match columnLabel")
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
}
if numPrimaryKey > 1 {
err = errors.New("duplicate primaryKey with other field")
err = errors.New("InputDefinition can only contain one PrimaryKey")
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
@ -1576,7 +1575,7 @@ func (h *Handler) handleGetInputDefinition(w http.ResponseWriter, r *http.Reques
indexName := mux.Vars(r)["index"]
inputDefName := mux.Vars(r)["input-definition"]
//Find index.
// Find index.
index := h.Holder.Index(indexName)
if index == nil {
if err := json.NewEncoder(w).Encode(deleteIndexResponse{}); err != nil {
@ -1620,7 +1619,7 @@ func (h *Handler) handleDeleteInputDefinition(w http.ResponseWriter, r *http.Req
Name: inputDefName,
})
if err != nil {
h.logger().Printf("problem sending CreateInputDefinition message: %s", err)
h.logger().Printf("problem sending DeleteInputDefinition message: %s", err)
}
if err := json.NewEncoder(w).Encode(postInputDefinitionResponse{}); err != nil {

View file

@ -1115,7 +1115,7 @@ func TestHandler_CreateInputDefinition(t *testing.T) {
}
//Ensure throwing error if there's duplicated primaryKey field
// Ensure throwing error if there's duplicated primaryKey field.
func TestHandler_DuplicatePrimaryKey(t *testing.T) {
hldr := MustOpenHolder()
defer hldr.Close()
@ -1148,12 +1148,12 @@ func TestHandler_DuplicatePrimaryKey(t *testing.T) {
h.ServeHTTP(w, MustNewHTTPRequest("POST", "/index/i0/input-definition/input2", bytes.NewBuffer(inputBody1)))
if w.Code != http.StatusBadRequest {
t.Fatalf("unexpected status code: %d", w.Code)
} else if body := w.Body.String(); body != `duplicate primaryKey with other field`+"\n" {
} else if body := w.Body.String(); body != `InputDefinition can only contain one PrimaryKey`+"\n" {
t.Fatalf("unexpected body: %s", body)
}
}
// Eusure throwing error if primary field's name doesn't match columnLabel
// Eusure throwing error if primary field's name doesn't match columnLabel.
func TestHandler_UnmatchColumnID(t *testing.T) {
hldr := MustOpenHolder()
defer hldr.Close()
@ -1182,7 +1182,7 @@ func TestHandler_UnmatchColumnID(t *testing.T) {
h.ServeHTTP(w, MustNewHTTPRequest("POST", "/index/i0/input-definition/input1", bytes.NewBuffer(inputBody)))
if w.Code != http.StatusBadRequest {
t.Fatalf("unexpected status code: %d", w.Code)
} else if body := w.Body.String(); body != `primary field's name not match columnLabel`+"\n" {
} else if body := w.Body.String(); body != `PrimaryKey field name does not match columnLabel`+"\n" {
t.Fatalf("unexpected body: %s", body)
}

View file

@ -51,14 +51,14 @@ type Index struct {
// Frames by name.
frames map[string]*Frame
// Max Slice on any node in the cluster, according to this node
// Max Slice on any node in the cluster, according to this node.
remoteMaxSlice uint64
remoteMaxInverseSlice uint64
// Column attribute storage and cache
// Column attribute storage and cache.
columnAttrStore *AttrStore
// InputDefinition by name
// InputDefinitions by name.
inputDefinitions map[string]*InputDefinition
broadcaster Broadcaster
@ -336,7 +336,7 @@ func (i *Index) SetTimeQuantum(q TimeQuantum) error {
// FramePath returns the path to a frame in the index.
func (i *Index) FramePath(name string) string { return filepath.Join(i.path, name) }
// InputDefinitionPath returns the path to a inputdefinition in the index.
// InputDefinitionPath returns the path to an input definition in the index.
func (i *Index) InputDefinitionPath() string {
return filepath.Join(i.path, InputDefinitionDir)
}
@ -618,10 +618,10 @@ type IndexOptions struct {
}
// Encode converts i into its internal representation.
func (o *IndexOptions) Encode() *internal.IndexMeta {
func (i *IndexOptions) Encode() *internal.IndexMeta {
return &internal.IndexMeta{
ColumnLabel: o.ColumnLabel,
TimeQuantum: string(o.TimeQuantum),
ColumnLabel: i.ColumnLabel,
TimeQuantum: string(i.TimeQuantum),
}
}
@ -702,7 +702,7 @@ func (i *Index) newInputDefinition(name string) (*InputDefinition, error) {
return inputDef, nil
}
// DeleteInputDefinition removes a input definition from the index.
// DeleteInputDefinition removes an input definition from the index.
func (i *Index) DeleteInputDefinition(name string) error {
i.mu.Lock()
defer i.mu.Unlock()
@ -742,7 +742,7 @@ func (i *Index) openInputDefinition() error {
input.Open()
i.inputDefinitions[file.Name()] = input
// Create frame if it doesn't exist
// Create frame if it doesn't exist.
for _, fr := range input.frames {
_, err := i.CreateFrame(fr.Name, fr.Options)
if err == ErrFrameExists {

View file

@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/pilosa/pilosa/internal"
)
@ -80,7 +81,7 @@ func (i *InputDefinition) Open() error {
return nil
}
// LoadDefinition loads the protobuf format of a defition
// LoadDefinition loads the protobuf format of a definition.
func (i *InputDefinition) LoadDefinition(pb *internal.InputDefinition) error {
// Copy metadata fields.
i.name = pb.Name
@ -146,7 +147,7 @@ func (i *InputDefinition) loadMeta() error {
return i.LoadDefinition(&pb)
}
//saveMeta writes meta data for the input definition file.
// 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
@ -223,7 +224,7 @@ func (o *InputDefinitionField) Encode() (*internal.InputDefinitionField, error)
return &field, nil
}
// Action descripes the mapping method for the field in the InputDefinition.
// Action describes the mapping method for the field in the InputDefinition.
type Action struct {
Frame string `json:"frame,omitempty"`
ValueDestination string `json:"valueDestination,omitempty"`
@ -258,7 +259,7 @@ type InputFrame struct {
Options FrameOptions `json:"options,omitempty"`
}
// InputDefinitionInfo the json message format to create an InputDefinition.
// InputDefinitionInfo represents the json message format needed to create an InputDefinition.
type InputDefinitionInfo struct {
Frames []InputFrame `json:"frames"`
Fields []InputDefinitionField `json:"fields"`
@ -281,7 +282,7 @@ func (i *InputDefinitionInfo) Encode() (*internal.InputDefinition, error) {
return &def, nil
}
// AddFrame adds frame to input definition
// AddFrame adds frame to input definition.
func (i *InputDefinition) AddFrame(frame InputFrame) error {
i.frames = append(i.frames, frame)
if err := i.saveMeta(); err != nil {
@ -290,7 +291,7 @@ func (i *InputDefinition) AddFrame(frame InputFrame) error {
return nil
}
// ValidateAction validate actions from input-definition
// ValidateAction validates actions from InputDefinition.
func (i *InputDefinition) ValidateAction(action *internal.InputDefinitionAction) error {
if action.Frame == "" {
return ErrFrameRequired