-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Properly handle multi fields in block loaders with synthetic source enabled #127483
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
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6cc34a5
Remove legacy block loader test infrastructure
lkts da14832
iter
lkts 2fd99a5
wip
lkts bbeb2ca
iter
lkts bdec7d8
Merge branch 'main' into multi_field_block_loader_tests
lkts 4113b9d
fix
lkts 8a265f9
iter
lkts 1ab6934
Merge branch 'main' into multi_field_block_loader_tests
lkts bc47394
Merge branch 'main' into multi_field_block_loader_tests
lkts 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,51 +9,108 @@ | |
|
|
||
| package org.elasticsearch.index.mapper.blockloader; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
|
|
||
| import org.elasticsearch.datageneration.DocumentGenerator; | ||
| import org.elasticsearch.datageneration.FieldType; | ||
| import org.elasticsearch.datageneration.MappingGenerator; | ||
| import org.elasticsearch.datageneration.Template; | ||
| import org.elasticsearch.datageneration.datasource.DataSourceHandler; | ||
| import org.elasticsearch.datageneration.datasource.DataSourceRequest; | ||
| import org.elasticsearch.datageneration.datasource.DataSourceResponse; | ||
| import org.elasticsearch.datageneration.datasource.DefaultMappingParametersHandler; | ||
| import org.elasticsearch.index.mapper.BlockLoaderTestCase; | ||
| import org.elasticsearch.index.mapper.BlockLoaderTestRunner; | ||
| import org.elasticsearch.index.mapper.MapperServiceTestCase; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
| import org.elasticsearch.xcontent.XContentType; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class TextFieldWithParentBlockLoaderTests extends BlockLoaderTestCase { | ||
| public TextFieldWithParentBlockLoaderTests(Params params) { | ||
| // keyword because we need a keyword parent field | ||
| super(FieldType.KEYWORD.toString(), List.of(new DataSourceHandler() { | ||
| import static org.elasticsearch.index.mapper.BlockLoaderTestCase.buildSpecification; | ||
| import static org.elasticsearch.index.mapper.BlockLoaderTestCase.hasDocValues; | ||
|
|
||
| public class TextFieldWithParentBlockLoaderTests extends MapperServiceTestCase { | ||
|
Contributor
Author
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. This is now a dedicated test for this case and it does not include "normal" tests that are covered in |
||
| private final BlockLoaderTestCase.Params params; | ||
| private final BlockLoaderTestRunner runner; | ||
|
|
||
| @ParametersFactory(argumentFormatting = "preference=%s") | ||
| public static List<Object[]> args() { | ||
| return BlockLoaderTestCase.args(); | ||
| } | ||
|
|
||
| public TextFieldWithParentBlockLoaderTests(BlockLoaderTestCase.Params params) { | ||
| this.params = params; | ||
| this.runner = new BlockLoaderTestRunner(params); | ||
| } | ||
|
|
||
| // This is similar to BlockLoaderTestCase#testBlockLoaderOfMultiField but has customizations required to properly test the case | ||
| // of text multi field in a keyword field. | ||
| public void testBlockLoaderOfParentField() throws IOException { | ||
| var template = new Template(Map.of("parent", new Template.Leaf("parent", FieldType.KEYWORD.toString()))); | ||
| var specification = buildSpecification(List.of(new DataSourceHandler() { | ||
| @Override | ||
| public DataSourceResponse.LeafMappingParametersGenerator handle(DataSourceRequest.LeafMappingParametersGenerator request) { | ||
| assert request.fieldType().equals(FieldType.KEYWORD.toString()); | ||
| // This is a bit tricky meta-logic. | ||
| // We want to customize mapping but to do this we need the mapping for the same field type | ||
| // so we use name to untangle this. | ||
| if (request.fieldName().equals("parent") == false) { | ||
| return null; | ||
| } | ||
|
|
||
| // We need to force multi field generation | ||
| return new DataSourceResponse.LeafMappingParametersGenerator(() -> { | ||
| var defaultSupplier = DefaultMappingParametersHandler.keywordMapping( | ||
| request, | ||
| DefaultMappingParametersHandler.commonMappingParameters() | ||
| ); | ||
| var mapping = defaultSupplier.get(); | ||
| var dataSource = request.dataSource(); | ||
|
|
||
| var keywordParentMapping = dataSource.get( | ||
| new DataSourceRequest.LeafMappingParametersGenerator( | ||
| dataSource, | ||
| "_field", | ||
| FieldType.KEYWORD.toString(), | ||
| request.eligibleCopyToFields(), | ||
| request.dynamicMapping() | ||
| ) | ||
| ).mappingGenerator().get(); | ||
|
|
||
| var textMultiFieldMapping = dataSource.get( | ||
| new DataSourceRequest.LeafMappingParametersGenerator( | ||
| dataSource, | ||
| "_field", | ||
| FieldType.TEXT.toString(), | ||
| request.eligibleCopyToFields(), | ||
| request.dynamicMapping() | ||
| ) | ||
| ).mappingGenerator().get(); | ||
|
|
||
| // we don't need this here | ||
| mapping.remove("copy_to"); | ||
| keywordParentMapping.remove("copy_to"); | ||
|
|
||
| var textMultiFieldMappingSupplier = DefaultMappingParametersHandler.textMapping(request, new HashMap<>()); | ||
| var textMultiFieldMapping = textMultiFieldMappingSupplier.get(); | ||
| textMultiFieldMapping.put("type", "text"); | ||
| textMultiFieldMapping.remove("fields"); | ||
|
|
||
| mapping.put("fields", Map.of("txt", textMultiFieldMapping)); | ||
| keywordParentMapping.put("fields", Map.of("mf", textMultiFieldMapping)); | ||
|
|
||
| return mapping; | ||
| return keywordParentMapping; | ||
| }); | ||
| } | ||
| }), params); | ||
| })); | ||
| var mapping = new MappingGenerator(specification).generate(template); | ||
| var fieldMapping = mapping.lookup().get("parent"); | ||
|
|
||
| var document = new DocumentGenerator(specification).generate(template, mapping); | ||
| var fieldValue = document.get("parent"); | ||
|
|
||
| Object expected = expected(fieldMapping, fieldValue, new BlockLoaderTestCase.TestContext(false, true)); | ||
| var mappingXContent = XContentBuilder.builder(XContentType.JSON.xContent()).map(mapping.raw()); | ||
| var mapperService = params.syntheticSource() | ||
| ? createSytheticSourceMapperService(mappingXContent) | ||
| : createMapperService(mappingXContent); | ||
|
|
||
| runner.runTest(mapperService, document, expected, "parent.mf"); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| protected Object expected(Map<String, Object> fieldMapping, Object value, TestContext testContext) { | ||
| private Object expected(Map<String, Object> fieldMapping, Object value, BlockLoaderTestCase.TestContext testContext) { | ||
| assert fieldMapping.containsKey("fields"); | ||
|
|
||
| Object normalizer = fieldMapping.get("normalizer"); | ||
|
|
@@ -66,12 +123,7 @@ protected Object expected(Map<String, Object> fieldMapping, Object value, TestCo | |
| } | ||
|
|
||
| // we are using block loader of the text field itself | ||
| var textFieldMapping = (Map<String, Object>) ((Map<String, Object>) fieldMapping.get("fields")).get("txt"); | ||
| var textFieldMapping = (Map<String, Object>) ((Map<String, Object>) fieldMapping.get("fields")).get("mf"); | ||
| return TextFieldBlockLoaderTests.expectedValue(textFieldMapping, value, params, testContext); | ||
| } | ||
|
|
||
| @Override | ||
| protected String blockLoaderFieldName(String originalName) { | ||
| return originalName + ".txt"; | ||
| } | ||
| } | ||
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
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.
This is actually a fix for an edge case that the new test finds.