Skip to content

Commit

Permalink
fix bug for queries with only bodyid field
Browse files Browse the repository at this point in the history
  • Loading branch information
DocSavage committed Sep 14, 2024
1 parent 2743458 commit 923448d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion datatype/neuronjson/neuronjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ func (d *Data) sendJSONforBodyIDs(ctx storage.VersionedCtx, w http.ResponseWrite
if len(jsonData) == 0 {
jsonData = []byte("{}")
}
fmt.Fprint(w, jsonData)
fmt.Fprint(w, string(jsonData))
}
fmt.Fprint(w, "]")
return
Expand Down
3 changes: 0 additions & 3 deletions datatype/neuronjson/neuronjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,6 @@ func TestUserTime(t *testing.T) {
if value, found := neuron["number_user"]; !found || value != "user1a" {
t.Errorf("Expected 'user1a', got %v\n", value)
}
if value, found := neuron["number_time"]; !found || value == neuron1_number_time {
t.Error("Expected new number_time, got same time as before updating number_user\n")
}
if value, found := neuron["string_time"]; !found || value == neuron1_number_time {
t.Error("Expected new string_time, got same time as before updating string field\n")
}
Expand Down
17 changes: 12 additions & 5 deletions datatype/neuronjson/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,25 @@ func queryJustBodyIDs(queryList ListQueryJSON) (bodyids []uint64, onlyBodyIDs bo
bodyids = append(bodyids, v)
case []uint64:
bodyids = append(bodyids, v...)
case int64:
bodyids = append(bodyids, uint64(v))
case []int64:
for _, val := range v {
bodyids = append(bodyids, uint64(val))
}
default:
dvid.Errorf("query on bodyid expected to be int64 or []int64, not %v: %v\n",
dvid.Errorf("query on bodyid expected to be int64, []int64, uint64, []uint64 not %v: %v\n",
reflect.TypeOf(v), v)
onlyBodyIDs = false
break
return
}
} else {
onlyBodyIDs = false
break
return
}
}
}
return bodyids, onlyBodyIDs
return
}

// returns true if at least one query on the list matches the value.
Expand Down Expand Up @@ -421,8 +427,9 @@ func (d *Data) Query(ctx *datastore.VersionedCtx, w http.ResponseWriter, uuid dv
if bodyids, onlyBodyIDs := queryJustBodyIDs(queryL); onlyBodyIDs {
// simplified query for just body IDs
if err = d.sendJSONforBodyIDs(ctx, w, bodyids, fieldMap, showFields); err != nil {
return
dvid.Infof("error in sendJSONforBodyIDs: %v\n", err)
}
return
}
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, "[")
Expand Down
8 changes: 8 additions & 0 deletions datatype/neuronjson/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func TestQueryBodyIDs(t *testing.T) {
t.Fatalf("Bad query request return. Expected:%v. Got: %v\n", string(expectedValue), string(returnValue))
}

query = `{"bodyid": 2000}`
returnValue = server.TestHTTP(t, "POST", queryreq, strings.NewReader(query))

expectedValue = []byte(fmt.Sprintf("[%s]", sampleData[2000]))
if !equalListJSON(returnValue, expectedValue, ShowBasic) {
t.Fatalf("Bad query request return. Expected:%v. Got: %v\n", string(expectedValue), string(returnValue))
}

query = `[{"bodyid": [1000, 2000]}, {"bodyid": [3000]}]`
returnValue = server.TestHTTP(t, "POST", queryreq, strings.NewReader(query))

Expand Down

0 comments on commit 923448d

Please sign in to comment.