Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix query string regex queries incorrectly swallowing TooComplexToDeterminizeException ([#18883](https://github.com/opensearch-project/OpenSearch/pull/18883))
- Fix socks5 user password settings for Azure repo ([#18904](https://github.com/opensearch-project/OpenSearch/pull/18904))
- Reset isPipelineResolved to false to resolve the system ingest pipeline again. ([#18911](https://github.com/opensearch-project/OpenSearch/pull/18911))
- Bug fix for `scaled_float` in `encodePoint` method ([#18952](https://github.com/opensearch-project/OpenSearch/pull/18952))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public byte[] encodePoint(Number value) {

@Override
public byte[] encodePoint(Object value, boolean roundUp) {
double doubleValue = parse(value);
long scaledValue = Math.round(scale(doubleValue));
long scaledValue = Math.round(scale(value));
if (roundUp) {
if (scaledValue < Long.MAX_VALUE) {
scaledValue = scaledValue + 1;
Expand All @@ -230,7 +229,9 @@ public byte[] encodePoint(Object value, boolean roundUp) {
scaledValue = scaledValue - 1;
}
}
return encodePoint(scaledValue);
byte[] point = new byte[Long.BYTES];
LongPoint.encodeDimension(scaledValue, point, 0);
return point;
}

public double getScalingFactor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.index.mapper;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.DirectoryReader;
Expand Down Expand Up @@ -473,4 +474,19 @@ public void testRejectIndexOptions() {
assertThat(e.getMessage(), containsString("Failed to parse mapping [_doc]: Field [scaling_factor] is required"));
assertWarnings("Parameter [index_options] has no effect on type [scaled_float] and will be removed in future");
}

public void testScaledFloatEncodePoint() {
double scalingFactor = 100.0;
ScaledFloatFieldMapper.ScaledFloatFieldType fieldType = new ScaledFloatFieldMapper.ScaledFloatFieldType(
"test_field",
scalingFactor
);
double originalValue = 10.5;
byte[] encodedRoundUp = fieldType.encodePoint(originalValue, true);
byte[] encodedRoundDown = fieldType.encodePoint(originalValue, false);
long decodedUp = LongPoint.decodeDimension(encodedRoundUp, 0);
long decodedDown = LongPoint.decodeDimension(encodedRoundDown, 0);
assertEquals(1051, decodedUp); // 10.5 scaled = 1050, then +1 = 1051 (represents 10.51)
assertEquals(1049, decodedDown); // 10.5 scaled = 1050, then -1 = 1049 (represents 10.49)
}
}
3 changes: 2 additions & 1 deletion release-notes/opensearch.release-notes-3.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@ Compatible with OpenSearch and OpenSearch Dashboards version 3.2.0
* Close IndexFieldDataService asynchronously ([#18888](https://github.com/opensearch-project/OpenSearch/pull/18888))
* Fix query string regex queries incorrectly swallowing TooComplexToDeterminizeException ([#18883](https://github.com/opensearch-project/OpenSearch/pull/18883))
* Fix socks5 user password settings for Azure repo ([#18904](https://github.com/opensearch-project/OpenSearch/pull/18904))
* Reset isPipelineResolved to false to resolve the system ingest pipeline again. ([#18911](https://github.com/opensearch-project/OpenSearch/pull/18911))
* Reset isPipelineResolved to false to resolve the system ingest pipeline again. ([#18911](https://github.com/opensearch-project/OpenSearch/pull/18911))
* Bug fix for `scaled_float` in `encodePoint` method ([#18952](https://github.com/opensearch-project/OpenSearch/pull/18952))
Loading