Skip to content

Commit

Permalink
Fix docvalue fetch for scaled floats (#62425)
Browse files Browse the repository at this point in the history
In #61995 I moved the `docvalue_field` fetch code into a place where I
could share it with the fancy new `fields` fetch API. Specifically,
runtime fields can use it all that doc values code now. But I broke
`scaled_floats` by switching them how they are fetched from `double` to
`string`. This adds the override you need to switch them back.
  • Loading branch information
nik9000 authored Sep 16, 2020
1 parent 1f03fdc commit 8a9028c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,25 @@ public int docValueCount() {
}
}

@Override
public DocValueFetcher.Leaf getLeafValueFetcher(DocValueFormat format) {
SortedNumericDoubleValues values = getDoubleValues();
return new DocValueFetcher.Leaf() {
@Override
public boolean advanceExact(int docId) throws IOException {
return values.advanceExact(docId);
}

@Override
public int docValueCount() throws IOException {
return values.docValueCount();
}

@Override
public Object nextValue() throws IOException {
return format.format(values.nextValue());
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,15 @@ setup:
- match: { hits.total.value: 4 }
- match: { hits.hits.0._id: "3" }
- match: { hits.hits.0.sort.0: -2 }

---
"docvalue_fields":

- do:
search:
body:
docvalue_fields: [ "number" ]
sort:
number:
order: asc
- match: { hits.hits.0.fields.number: [-2.1] }
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setup:
index:
index: test_1
id: 1
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1, "bigint": 72057594037927936 }
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1, "bigint": 72057594037927936, d: 3.14 }
- do:
indices.refresh: {}

Expand Down Expand Up @@ -175,3 +175,16 @@ setup:
- field: "count"
format: "#.0"
- match: { hits.hits.0.fields.count: ["1.0"] }

---
"docvalue_fields - double":

- do:
search:
body:
docvalue_fields: [ "d" ]
# Doc values produce floating point errors.
# When this test is run during runtime-field's tests we *don't* get floating point errors. Thus the funny assertion here that matches both.
- lt: { hits.hits.0.fields.d.0: 3.141 }
- gte: { hits.hits.0.fields.d.0: 3.14 }

0 comments on commit 8a9028c

Please sign in to comment.