-
Couldn't load subscription status.
- Fork 25.6k
Store arrays offsets for scaled float fields natively with synthetic source #125793
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
Merged
jordan-powers
merged 9 commits into
elastic:main
from
jordan-powers:offset-encoding-scaled-float
Mar 28, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
700a15b
Initial implementation of offset encoding for scaled float fields
jordan-powers a917387
Add mechanism to include other mapping parameters in offset tests
jordan-powers 11ed0ea
Add offset tests for scaled float
jordan-powers b98a829
Fix ScaledFloatFieldMapperTests#testSyntheticSourceKeepArrays
jordan-powers ba8e223
Merge remote-tracking branch 'upstream/main' into offset-encoding-sca…
jordan-powers 0546fc9
Simplify scaled float getRandomValue in offset encoding tests
jordan-powers 529f5af
Merge remote-tracking branch 'upstream/main' into offset-encoding-sca…
jordan-powers 5f25c3b
Address review comments
jordan-powers e01cfb6
Merge remote-tracking branch 'upstream/main' into offset-encoding-sca…
jordan-powers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...est/java/org/elasticsearch/index/mapper/extras/ScaledFloatOffsetDocValuesLoaderTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.mapper.extras; | ||
|
|
||
| import org.elasticsearch.index.mapper.OffsetDocValuesLoaderTestCase; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
|
|
||
| public class ScaledFloatOffsetDocValuesLoaderTests extends OffsetDocValuesLoaderTestCase { | ||
| private static final double TEST_SCALING_FACTOR = 10.0; | ||
|
|
||
| @Override | ||
| protected Collection<? extends Plugin> getPlugins() { | ||
| return singletonList(new MapperExtrasPlugin()); | ||
| } | ||
|
|
||
| @Override | ||
| protected void minimalMapping(XContentBuilder b) throws IOException { | ||
| b.field("type", "scaled_float").field("scaling_factor", TEST_SCALING_FACTOR); | ||
| } | ||
|
|
||
| public void testOffsetArray() throws Exception { | ||
| verifyOffsets("{\"field\":[1.0,10.0,100.0,0.1,10.0,1.0,0.1,100.0]}"); | ||
| verifyOffsets("{\"field\":[10.0,null,1.0,null,5.0,null,null,6.3,1.5]}"); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getFieldTypeName() { | ||
| fail("Should not be called because minimalMapping is overridden"); | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| protected Double randomValue() { | ||
| return randomLong() / TEST_SCALING_FACTOR; | ||
| } | ||
| } | ||
51 changes: 51 additions & 0 deletions
51
...sticsearch/index/mapper/extras/ScaledFloatSyntheticSourceNativeArrayIntegrationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.mapper.extras; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.generators.RandomStrings; | ||
|
|
||
| import org.elasticsearch.index.mapper.NativeArrayIntegrationTestCase; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
|
|
||
| public class ScaledFloatSyntheticSourceNativeArrayIntegrationTests extends NativeArrayIntegrationTestCase { | ||
| private static final double TEST_SCALING_FACTOR = 10.0; | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> getPlugins() { | ||
| return singletonList(MapperExtrasPlugin.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected void minimalMapping(XContentBuilder b) throws IOException { | ||
| b.field("type", "scaled_float").field("scaling_factor", TEST_SCALING_FACTOR); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getFieldTypeName() { | ||
| fail("Should not be called because minimalMapping is overridden"); | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| protected Object getRandomValue() { | ||
| return randomLong() / TEST_SCALING_FACTOR; | ||
| } | ||
|
|
||
| @Override | ||
| protected Object getMalformedValue() { | ||
| return randomBoolean() ? RandomStrings.randomAsciiOfLength(random(), 8) : Double.POSITIVE_INFINITY; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why does this return null here?
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.
I see, because
minimalMapping(...)gets overwritten here. So actually this method should never be invoked. Maybe add anassert falsehere? So it fails quick if this gets invoked?