This commit is contained in:
Yuce Tekol 2017-11-14 19:15:17 +03:00
parent 7a5459da73
commit f756e9eee6
No known key found for this signature in database
GPG key ID: CB59E46D2FB90573
3 changed files with 7 additions and 11 deletions

View file

@ -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")
}

View file

@ -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

View file

@ -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()