-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Improve block loader for source only runtime fields of type double. #134629
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
Changes from 3 commits
46c9d6e
0757f9e
1950294
3d7bf4d
45a5e24
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 134629 | ||
| summary: Improve block loader for source only runtime fields of type double | ||
| area: Mapping | ||
| type: enhancement | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
|
|
||
| import java.time.ZoneId; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.function.Function; | ||
|
|
@@ -109,7 +110,35 @@ public DocValueFormat docValueFormat(String format, ZoneId timeZone) { | |
|
|
||
| @Override | ||
| public BlockLoader blockLoader(BlockLoaderContext blContext) { | ||
| return new DoubleScriptBlockDocValuesReader.DoubleScriptBlockLoader(leafFactory(blContext.lookup())); | ||
| var indexSettings = blContext.indexSettings(); | ||
| if (isParsedFromSource && indexSettings.getIndexMappingSourceMode() == SourceFieldMapper.Mode.SYNTHETIC | ||
| // A runtime and normal field can share the same name. | ||
| // In that case there is no ignored source entry, and so we need to fail back to LongScriptBlockLoader. | ||
| // We could optimize this, but at this stage feels like a rare scenario. | ||
| && blContext.lookup().onlyMappedAsRuntimeField(name())) { | ||
| var reader = new NumberType.NumberFallbackSyntheticSourceReader(NumberType.DOUBLE, null, true) { | ||
|
||
| @Override | ||
| public void writeToBlock(List<Number> values, BlockLoader.Builder blockBuilder) { | ||
| var builder = (BlockLoader.DoubleBuilder) blockBuilder; | ||
| for (var value : values) { | ||
| builder.appendDouble(value.doubleValue()); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return new FallbackSyntheticSourceBlockLoader( | ||
| reader, | ||
| name(), | ||
| IgnoredSourceFieldMapper.ignoredSourceFormat(indexSettings.getIndexVersionCreated()) | ||
| ) { | ||
| @Override | ||
| public Builder builder(BlockFactory factory, int expectedCount) { | ||
| return factory.doubles(expectedCount); | ||
| } | ||
| }; | ||
| } else { | ||
| return new DoubleScriptBlockDocValuesReader.DoubleScriptBlockLoader(leafFactory(blContext.lookup())); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
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.
nit: indentation
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.
This is how spotless formatted it :) I fixed the indentation, but since I copied from long script field type, I generalized the logic, it should be reusable for other runtime field types as well.