Fixed wrong order for fields with SCAN

This commit fixes an issue that happens when running SCAN on a
collection that has objects with fields, causing field values
to be mismatched with their respective keys.

This only occured with json output, and is a regression from #534.

Fixes #569
This commit is contained in:
tidwall 2020-07-04 10:12:06 -07:00
parent 1477026721
commit 67abcefd25
1 changed files with 3 additions and 2 deletions

View File

@ -399,13 +399,14 @@ func (sw *scanWriter) writeObject(opts ScanWriterParams) bool {
}
} else if len(sw.farr) > 0 {
fvs := orderFields(sw.fmap, sw.farr, opts.fields)
jsfields = `,"fields":[`
for i := range sw.farr {
for i, fv := range fvs {
if i > 0 {
jsfields += `,`
}
if len(opts.fields) > i {
jsfields += strconv.FormatFloat(opts.fields[i], 'f', -1, 64)
jsfields += strconv.FormatFloat(fv.value, 'f', -1, 64)
} else {
jsfields += "0"
}