MB-26396: Handling documents with geopoints in slice format
+ The issue lies with parsing documents containing a geopoint in slice format - which wasn't handled. + Unit test that verifies the fix.
This commit is contained in:
parent
5d1a2b0ad7
commit
6451c8c37f
|
@ -504,7 +504,7 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
|
||||||
}
|
}
|
||||||
dm.walkDocument(property, path, indexes, context)
|
dm.walkDocument(property, path, indexes, context)
|
||||||
}
|
}
|
||||||
case reflect.Map:
|
case reflect.Map, reflect.Slice:
|
||||||
if subDocMapping != nil {
|
if subDocMapping != nil {
|
||||||
for _, fieldMapping := range subDocMapping.Fields {
|
for _, fieldMapping := range subDocMapping.Fields {
|
||||||
if fieldMapping.Type == "geopoint" {
|
if fieldMapping.Type == "geopoint" {
|
||||||
|
|
|
@ -869,37 +869,65 @@ func TestMappingForGeo(t *testing.T) {
|
||||||
mapping := NewIndexMapping()
|
mapping := NewIndexMapping()
|
||||||
mapping.DefaultMapping = thingMapping
|
mapping.DefaultMapping = thingMapping
|
||||||
|
|
||||||
x := struct {
|
geopoints := []interface{}{}
|
||||||
|
|
||||||
|
// geopoint as a struct
|
||||||
|
geopoints = append(geopoints, struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Location *Location `json:"location"`
|
Location *Location `json:"location"`
|
||||||
}{
|
}{
|
||||||
Name: "marty",
|
Name: "struct",
|
||||||
Location: &Location{
|
Location: &Location{
|
||||||
Lon: -180,
|
Lon: -180,
|
||||||
Lat: -90,
|
Lat: -90,
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
doc := document.NewDocument("1")
|
// geopoint as a map
|
||||||
err := mapping.MapDocument(doc, x)
|
geopoints = append(geopoints, struct {
|
||||||
if err != nil {
|
Name string `json:"name"`
|
||||||
t.Fatal(err)
|
Location map[string]interface{} `json:"location"`
|
||||||
}
|
}{
|
||||||
|
Name: "map",
|
||||||
|
Location: map[string]interface{}{
|
||||||
|
"lon": -180,
|
||||||
|
"lat": -90,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
var foundGeo bool
|
// geopoint as a slice
|
||||||
for _, f := range doc.Fields {
|
geopoints = append(geopoints, struct {
|
||||||
if f.Name() == "location" {
|
Name string `json:"name"`
|
||||||
foundGeo = true
|
Location []interface{} `json:"location"`
|
||||||
got := f.Value()
|
}{
|
||||||
expect := []byte(numeric.MustNewPrefixCodedInt64(0, 0))
|
Name: "slice",
|
||||||
if !reflect.DeepEqual(got, expect) {
|
Location: []interface{}{
|
||||||
t.Errorf("expected geo value: %v, got %v", expect, got)
|
-180, -90,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
for i, geopoint := range geopoints {
|
||||||
|
doc := document.NewDocument(string(i))
|
||||||
|
err := mapping.MapDocument(doc, geopoint)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var foundGeo bool
|
||||||
|
for _, f := range doc.Fields {
|
||||||
|
if f.Name() == "location" {
|
||||||
|
foundGeo = true
|
||||||
|
got := f.Value()
|
||||||
|
expect := []byte(numeric.MustNewPrefixCodedInt64(0, 0))
|
||||||
|
if !reflect.DeepEqual(got, expect) {
|
||||||
|
t.Errorf("expected geo value: %v, got %v", expect, got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !foundGeo {
|
if !foundGeo {
|
||||||
t.Errorf("expected to find geo point, did not")
|
t.Errorf("expected to find geo point, did not")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue