Skip to content

Commit 904552b

Browse files
committed
adjusted some of the InputDefinition comments
1 parent 53c7e59 commit 904552b

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

handler.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -1499,11 +1499,18 @@ func errorString(err error) string {
14991499
return err.Error()
15001500
}
15011501

1502-
// handlePOSTInputDefinition handles POST /input-definition request.
1502+
// handlePostInputDefinition handles POST /input-definition request.
15031503
func (h *Handler) handlePostInputDefinition(w http.ResponseWriter, r *http.Request) {
15041504
indexName := mux.Vars(r)["index"]
15051505
inputDefName := mux.Vars(r)["input-definition"]
15061506

1507+
// Find index.
1508+
index := h.Holder.Index(indexName)
1509+
if index == nil {
1510+
http.Error(w, ErrIndexNotFound.Error(), http.StatusNotFound)
1511+
return
1512+
}
1513+
15071514
// Decode request.
15081515
var req InputDefinitionInfo
15091516
err := json.NewDecoder(r.Body).Decode(&req)
@@ -1512,36 +1519,28 @@ func (h *Handler) handlePostInputDefinition(w http.ResponseWriter, r *http.Reque
15121519
return
15131520
}
15141521

1515-
// Find index.
1516-
index := h.Holder.Index(indexName)
1517-
if index == nil {
1518-
http.Error(w, ErrIndexNotFound.Error(), http.StatusNotFound)
1519-
return
1520-
}
1521-
1522+
// Encode InputDefinition to its internal representation.
15221523
def, err := req.Encode()
15231524
if err != nil {
15241525
http.Error(w, err.Error(), http.StatusInternalServerError)
15251526
return
15261527
}
15271528
def.Name = inputDefName
15281529

1529-
// Validate columnLabel & duplicate primaryKey
1530+
// Validate columnLabel and duplicate primaryKey.
15301531
numPrimaryKey := 0
15311532
for _, field := range def.Fields {
15321533
if field.PrimaryKey {
15331534
numPrimaryKey += 1
1534-
if field.Name == index.columnLabel {
1535-
continue
1536-
} else {
1537-
err = fmt.Errorf("primary field's name not match columnLabel")
1535+
if field.Name != index.columnLabel {
1536+
err = fmt.Errorf("PrimaryKey field name does not match columnLabel")
15381537
http.Error(w, err.Error(), http.StatusBadRequest)
15391538
return
15401539
}
15411540
}
15421541
}
15431542
if numPrimaryKey > 1 {
1544-
err = errors.New("duplicate primaryKey with other field")
1543+
err = errors.New("InputDefinition can only contain one PrimaryKey")
15451544
http.Error(w, err.Error(), http.StatusBadRequest)
15461545
return
15471546
}
@@ -1576,7 +1575,7 @@ func (h *Handler) handleGetInputDefinition(w http.ResponseWriter, r *http.Reques
15761575
indexName := mux.Vars(r)["index"]
15771576
inputDefName := mux.Vars(r)["input-definition"]
15781577

1579-
//Find index.
1578+
// Find index.
15801579
index := h.Holder.Index(indexName)
15811580
if index == nil {
15821581
if err := json.NewEncoder(w).Encode(deleteIndexResponse{}); err != nil {
@@ -1620,7 +1619,7 @@ func (h *Handler) handleDeleteInputDefinition(w http.ResponseWriter, r *http.Req
16201619
Name: inputDefName,
16211620
})
16221621
if err != nil {
1623-
h.logger().Printf("problem sending CreateInputDefinition message: %s", err)
1622+
h.logger().Printf("problem sending DeleteInputDefinition message: %s", err)
16241623
}
16251624

16261625
if err := json.NewEncoder(w).Encode(postInputDefinitionResponse{}); err != nil {

handler_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ func TestHandler_CreateInputDefinition(t *testing.T) {
11151115

11161116
}
11171117

1118-
//Ensure throwing error if there's duplicated primaryKey field
1118+
// Ensure throwing error if there's duplicated primaryKey field.
11191119
func TestHandler_DuplicatePrimaryKey(t *testing.T) {
11201120
hldr := MustOpenHolder()
11211121
defer hldr.Close()
@@ -1148,12 +1148,12 @@ func TestHandler_DuplicatePrimaryKey(t *testing.T) {
11481148
h.ServeHTTP(w, MustNewHTTPRequest("POST", "/index/i0/input-definition/input2", bytes.NewBuffer(inputBody1)))
11491149
if w.Code != http.StatusBadRequest {
11501150
t.Fatalf("unexpected status code: %d", w.Code)
1151-
} else if body := w.Body.String(); body != `duplicate primaryKey with other field`+"\n" {
1151+
} else if body := w.Body.String(); body != `InputDefinition can only contain one PrimaryKey`+"\n" {
11521152
t.Fatalf("unexpected body: %s", body)
11531153
}
11541154
}
11551155

1156-
// Eusure throwing error if primary field's name doesn't match columnLabel
1156+
// Eusure throwing error if primary field's name doesn't match columnLabel.
11571157
func TestHandler_UnmatchColumnID(t *testing.T) {
11581158
hldr := MustOpenHolder()
11591159
defer hldr.Close()
@@ -1182,7 +1182,7 @@ func TestHandler_UnmatchColumnID(t *testing.T) {
11821182
h.ServeHTTP(w, MustNewHTTPRequest("POST", "/index/i0/input-definition/input1", bytes.NewBuffer(inputBody)))
11831183
if w.Code != http.StatusBadRequest {
11841184
t.Fatalf("unexpected status code: %d", w.Code)
1185-
} else if body := w.Body.String(); body != `primary field's name not match columnLabel`+"\n" {
1185+
} else if body := w.Body.String(); body != `PrimaryKey field name does not match columnLabel`+"\n" {
11861186
t.Fatalf("unexpected body: %s", body)
11871187
}
11881188

index.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ type Index struct {
5151
// Frames by name.
5252
frames map[string]*Frame
5353

54-
// Max Slice on any node in the cluster, according to this node
54+
// Max Slice on any node in the cluster, according to this node.
5555
remoteMaxSlice uint64
5656
remoteMaxInverseSlice uint64
5757

58-
// Column attribute storage and cache
58+
// Column attribute storage and cache.
5959
columnAttrStore *AttrStore
6060

61-
// InputDefinition by name
61+
// InputDefinitions by name.
6262
inputDefinitions map[string]*InputDefinition
6363

6464
broadcaster Broadcaster
@@ -336,7 +336,7 @@ func (i *Index) SetTimeQuantum(q TimeQuantum) error {
336336
// FramePath returns the path to a frame in the index.
337337
func (i *Index) FramePath(name string) string { return filepath.Join(i.path, name) }
338338

339-
// InputDefinitionPath returns the path to a inputdefinition in the index.
339+
// InputDefinitionPath returns the path to an input definition in the index.
340340
func (i *Index) InputDefinitionPath() string {
341341
return filepath.Join(i.path, InputDefinitionDir)
342342
}
@@ -618,10 +618,10 @@ type IndexOptions struct {
618618
}
619619

620620
// Encode converts i into its internal representation.
621-
func (o *IndexOptions) Encode() *internal.IndexMeta {
621+
func (i *IndexOptions) Encode() *internal.IndexMeta {
622622
return &internal.IndexMeta{
623-
ColumnLabel: o.ColumnLabel,
624-
TimeQuantum: string(o.TimeQuantum),
623+
ColumnLabel: i.ColumnLabel,
624+
TimeQuantum: string(i.TimeQuantum),
625625
}
626626
}
627627

@@ -702,7 +702,7 @@ func (i *Index) newInputDefinition(name string) (*InputDefinition, error) {
702702
return inputDef, nil
703703
}
704704

705-
// DeleteInputDefinition removes a input definition from the index.
705+
// DeleteInputDefinition removes an input definition from the index.
706706
func (i *Index) DeleteInputDefinition(name string) error {
707707
i.mu.Lock()
708708
defer i.mu.Unlock()
@@ -742,7 +742,7 @@ func (i *Index) openInputDefinition() error {
742742
input.Open()
743743
i.inputDefinitions[file.Name()] = input
744744

745-
// Create frame if it doesn't exist
745+
// Create frame if it doesn't exist.
746746
for _, fr := range input.frames {
747747
_, err := i.CreateFrame(fr.Name, fr.Options)
748748
if err == ErrFrameExists {

input_definition.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"errors"
2323
"fmt"
24+
2425
"github.com/gogo/protobuf/proto"
2526
"github.com/pilosa/pilosa/internal"
2627
)
@@ -80,7 +81,7 @@ func (i *InputDefinition) Open() error {
8081
return nil
8182
}
8283

83-
// LoadDefinition loads the protobuf format of a defition
84+
// LoadDefinition loads the protobuf format of a definition.
8485
func (i *InputDefinition) LoadDefinition(pb *internal.InputDefinition) error {
8586
// Copy metadata fields.
8687
i.name = pb.Name
@@ -146,7 +147,7 @@ func (i *InputDefinition) loadMeta() error {
146147
return i.LoadDefinition(&pb)
147148
}
148149

149-
//saveMeta writes meta data for the input definition file.
150+
// saveMeta writes meta data for the input definition file.
150151
func (i *InputDefinition) saveMeta() error {
151152
if err := os.MkdirAll(i.path, 0777); err != nil {
152153
return err
@@ -223,7 +224,7 @@ func (o *InputDefinitionField) Encode() (*internal.InputDefinitionField, error)
223224
return &field, nil
224225
}
225226

226-
// Action descripes the mapping method for the field in the InputDefinition.
227+
// Action describes the mapping method for the field in the InputDefinition.
227228
type Action struct {
228229
Frame string `json:"frame,omitempty"`
229230
ValueDestination string `json:"valueDestination,omitempty"`
@@ -258,7 +259,7 @@ type InputFrame struct {
258259
Options FrameOptions `json:"options,omitempty"`
259260
}
260261

261-
// InputDefinitionInfo the json message format to create an InputDefinition.
262+
// InputDefinitionInfo represents the json message format needed to create an InputDefinition.
262263
type InputDefinitionInfo struct {
263264
Frames []InputFrame `json:"frames"`
264265
Fields []InputDefinitionField `json:"fields"`
@@ -281,7 +282,7 @@ func (i *InputDefinitionInfo) Encode() (*internal.InputDefinition, error) {
281282
return &def, nil
282283
}
283284

284-
// AddFrame adds frame to input definition
285+
// AddFrame adds frame to input definition.
285286
func (i *InputDefinition) AddFrame(frame InputFrame) error {
286287
i.frames = append(i.frames, frame)
287288
if err := i.saveMeta(); err != nil {
@@ -290,7 +291,7 @@ func (i *InputDefinition) AddFrame(frame InputFrame) error {
290291
return nil
291292
}
292293

293-
// ValidateAction validate actions from input-definition
294+
// ValidateAction validates actions from InputDefinition.
294295
func (i *InputDefinition) ValidateAction(action *internal.InputDefinitionAction) error {
295296
if action.Frame == "" {
296297
return ErrFrameRequired

0 commit comments

Comments
 (0)