-
Notifications
You must be signed in to change notification settings - Fork 1
Scale doubles to floats when necessary to match the field (#78344) #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pr_018_before
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,13 +13,15 @@ | |
| import org.elasticsearch.index.fielddata.IndexGeoPointFieldData; | ||
| import org.elasticsearch.index.fielddata.IndexNumericFieldData; | ||
| import org.elasticsearch.index.mapper.MappedFieldType; | ||
| import org.elasticsearch.index.mapper.NumberFieldMapper; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard precision reduction to floating types to avoid integer-range regressions.
💡 Suggested fix- public DoubleUnaryOperator reduceToStoredPrecisionFunction() {
- if (fieldContext() != null && fieldType() instanceof NumberFieldMapper.NumberFieldType) {
- return ((NumberFieldMapper.NumberFieldType) fieldType())::reduceToStoredPrecision;
- }
- return (value) -> value;
- }
+ public DoubleUnaryOperator reduceToStoredPrecisionFunction() {
+ if (fieldContext() != null && fieldType() instanceof NumberFieldMapper.NumberFieldType) {
+ NumberFieldMapper.NumberFieldType nft = (NumberFieldMapper.NumberFieldType) fieldType();
+ IndexNumericFieldData.NumericType nt = nft.numericType();
+ if (nt == IndexNumericFieldData.NumericType.FLOAT
+ || nt == IndexNumericFieldData.NumericType.HALF_FLOAT
+ || nt == IndexNumericFieldData.NumericType.DOUBLE) {
+ return nft::reduceToStoredPrecision;
+ }
+ }
+ return DoubleUnaryOperator.identity();
+ }Also applies to: 24-24, 326-335 🤖 Prompt for AI Agents |
||
| import org.elasticsearch.index.mapper.RangeFieldMapper; | ||
| import org.elasticsearch.script.AggregationScript; | ||
| import org.elasticsearch.script.Script; | ||
| import org.elasticsearch.search.DocValueFormat; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.ZoneId; | ||
| import java.util.function.DoubleUnaryOperator; | ||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
|
|
@@ -321,6 +323,17 @@ public FieldContext fieldContext() { | |
| return fieldContext; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a function from the mapper that adjusts a double value to the value it would have been had it been parsed by that mapper | ||
| * and then cast up to a double. Used to correct precision errors. | ||
| */ | ||
| public DoubleUnaryOperator reduceToStoredPrecisionFunction() { | ||
| if (fieldContext() != null && fieldType() instanceof NumberFieldMapper.NumberFieldType) { | ||
| return ((NumberFieldMapper.NumberFieldType) fieldType())::reduceToStoredPrecision; | ||
| } | ||
| return (value) -> value; | ||
| } | ||
|
|
||
| /** | ||
| * Convenience method for looking up the mapped field type backing this values source, if it exists. | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null-safe precision fix + apply it to string bounds.
range.from/range.tocan be null for unbounded ranges, soapplyAsDoublewill NPE. Also, string overrides (fromAsStr/toAsStr) bypass the precision fix entirely. Both can break correctness for unbounded ranges and string-based inputs.✅ Proposed fix
Also applies to: 156-175
🤖 Prompt for AI Agents