From f756e9eee6554cff31a442b8236d080eeb50c343 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Tue, 14 Nov 2017 19:15:17 +0300 Subject: [PATCH] Updates --- handler.go | 6 +----- input_definition.go | 9 ++++----- input_definition_test.go | 3 ++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/handler.go b/handler.go index f0133a1c3..f3d9fe9d3 100644 --- a/handler.go +++ b/handler.go @@ -1907,11 +1907,7 @@ func (h *Handler) InputJSONDataParser(req map[string]interface{}, index *Index, for _, field := range inputDef.Fields() { validFields[field.Name] = true if field.PrimaryKey { - primaryKey := field.Name - if primaryKey != DefaultColumnLabel { - return nil, fmt.Errorf("Primary key field should have the name: %s", DefaultColumnLabel) - } - value, ok := req[primaryKey] + value, ok := req[field.Name] if !ok { return nil, fmt.Errorf("primary key does not exist") } diff --git a/input_definition.go b/input_definition.go index 0c5088614..84d22d4ac 100644 --- a/input_definition.go +++ b/input_definition.go @@ -105,7 +105,6 @@ func (i *InputDefinition) LoadDefinition(pb *internal.InputDefinition) error { for _, field := range pb.Fields { var actions []Action - fieldName := field.Name for _, action := range field.InputDefinitionActions { actions = append(actions, Action{ Frame: action.Frame, @@ -116,14 +115,11 @@ func (i *InputDefinition) LoadDefinition(pb *internal.InputDefinition) error { } if field.PrimaryKey { - // Deprecating column labels per #810. - // So, setting the default column label here. - fieldName = DefaultColumnLabel primaryKeyGiven = true } inputField := InputDefinitionField{ - Name: fieldName, + Name: field.Name, PrimaryKey: field.PrimaryKey, Actions: actions, } @@ -296,6 +292,9 @@ func (i *InputDefinitionInfo) Validate() error { // Validate columnLabel and duplicate primaryKey. for _, field := range i.Fields { + if field.Name == "" { + return ErrInputDefinitionNameRequired + } for _, action := range field.Actions { if err := action.Validate(); err != nil { return err diff --git a/input_definition_test.go b/input_definition_test.go index 4daf7ce89..93d0e393d 100644 --- a/input_definition_test.go +++ b/input_definition_test.go @@ -64,6 +64,7 @@ func TestInputDefinition_Encoding(t *testing.T) { }], "fields": [ { + "name": "id", "primaryKey": true }, { @@ -173,7 +174,7 @@ func TestActionValidation(t *testing.T) { t.Fatalf("Expected duplicate rowID with other field error, actual error: %s", err) } - field = pilosa.InputDefinitionField{PrimaryKey: true} + field = pilosa.InputDefinitionField{Name: "id", PrimaryKey: true} field1 = pilosa.InputDefinitionField{Name: "test", PrimaryKey: false} info = pilosa.InputDefinitionInfo{Frames: []pilosa.InputFrame{frame}, Fields: []pilosa.InputDefinitionField{field, field1}} err = info.Validate()