-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Star tree] Support for keyword changes as part of star tree mapper #16103
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
Closed
bharath-techie
wants to merge
2
commits into
opensearch-project:main
from
bharath-techie:keyword-mapper
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
75 changes: 75 additions & 0 deletions
75
server/src/main/java/org/opensearch/index/compositeindex/datacube/KeywordDimension.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,75 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.index.compositeindex.datacube; | ||
|
|
||
| import org.opensearch.common.annotation.ExperimentalApi; | ||
| import org.opensearch.core.xcontent.XContentBuilder; | ||
| import org.opensearch.index.mapper.CompositeDataCubeFieldType; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.function.Consumer; | ||
|
|
||
| /** | ||
| * Composite index keyword dimension class | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| @ExperimentalApi | ||
| public class KeywordDimension implements Dimension { | ||
| public static final String KEYWORD = "keyword"; | ||
| private final String field; | ||
|
|
||
| public KeywordDimension(String field) { | ||
| this.field = field; | ||
| } | ||
|
|
||
| @Override | ||
| public String getField() { | ||
| return field; | ||
| } | ||
|
|
||
| @Override | ||
| public int getNumSubDimensions() { | ||
| return 1; | ||
| } | ||
|
|
||
| @Override | ||
| public void setDimensionValues(Long value, Consumer<Long> dimSetter) { | ||
| dimSetter.accept(value); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getSubDimensionNames() { | ||
| return List.of(field); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(CompositeDataCubeFieldType.NAME, field); | ||
| builder.field(CompositeDataCubeFieldType.TYPE, KEYWORD); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| KeywordDimension dimension = (KeywordDimension) o; | ||
| return Objects.equals(field, dimension.getField()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(field); | ||
|
Check warning on line 73 in server/src/main/java/org/opensearch/index/compositeindex/datacube/KeywordDimension.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
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
104 changes: 104 additions & 0 deletions
104
server/src/test/java/org/opensearch/index/compositeindex/datacube/DimensionFactoryTests.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,104 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.index.compositeindex.datacube; | ||
|
|
||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.index.mapper.Mapper; | ||
| import org.opensearch.test.OpenSearchTestCase; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class DimensionFactoryTests extends OpenSearchTestCase { | ||
|
|
||
| public void testParseAndCreateDateDimension() { | ||
| String name = "dateDimension"; | ||
| Map<String, Object> dimensionMap = new HashMap<>(); | ||
| List<String> calendarIntervals = Arrays.asList("day", "month"); | ||
| dimensionMap.put("calendar_intervals", calendarIntervals); | ||
|
|
||
| Mapper.TypeParser.ParserContext mockContext = mock(Mapper.TypeParser.ParserContext.class); | ||
| when(mockContext.getSettings()).thenReturn(Settings.EMPTY); | ||
|
|
||
| Dimension dimension = DimensionFactory.parseAndCreateDimension(name, DateDimension.DATE, dimensionMap, mockContext); | ||
|
|
||
| assertTrue(dimension instanceof DateDimension); | ||
| assertEquals(2, dimension.getNumSubDimensions()); | ||
| for (String interval : calendarIntervals) { | ||
| assertTrue(dimension.getSubDimensionNames().contains(name + "_" + interval)); | ||
| } | ||
| assertEquals(name, dimension.getField()); | ||
| DateDimension dateDimension = (DateDimension) dimension; | ||
| assertEquals(2, dateDimension.getIntervals().size()); | ||
| } | ||
|
|
||
| public void testParseAndCreateNumericDimension() { | ||
| String name = "numericDimension"; | ||
| Dimension dimension = DimensionFactory.parseAndCreateDimension(name, NumericDimension.NUMERIC, new HashMap<>(), null); | ||
|
|
||
| assertTrue(dimension instanceof NumericDimension); | ||
| assertEquals(1, dimension.getNumSubDimensions()); | ||
| assertTrue(dimension.getSubDimensionNames().contains(name)); | ||
| assertEquals(name, dimension.getField()); | ||
| } | ||
|
|
||
| public void testParseAndCreateKeywordDimension() { | ||
| String name = "keywordDimension"; | ||
| Dimension dimension = DimensionFactory.parseAndCreateDimension(name, KeywordDimension.KEYWORD, new HashMap<>(), null); | ||
| KeywordDimension kd = new KeywordDimension(name); | ||
| assertTrue(dimension instanceof KeywordDimension); | ||
| assertEquals(1, dimension.getNumSubDimensions()); | ||
| assertTrue(dimension.getSubDimensionNames().contains(name)); | ||
| assertEquals(dimension, kd); | ||
| assertEquals(name, dimension.getField()); | ||
| List<Long> dimValue = new ArrayList<>(); | ||
| kd.setDimensionValues(1L, dimValue::add); | ||
| assertEquals((Long) 1L, dimValue.get(0)); | ||
| } | ||
|
|
||
| public void testParseAndCreateDimensionWithUnsupportedType() { | ||
| String name = "unsupportedDimension"; | ||
| String unsupportedType = "unsupported"; | ||
|
|
||
| IllegalArgumentException exception = expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> DimensionFactory.parseAndCreateDimension(name, unsupportedType, new HashMap<>(), null) | ||
| ); | ||
| assertTrue(exception.getMessage().contains("unsupported field type")); | ||
| } | ||
|
|
||
| public void testParseAndCreateDimensionWithBuilder() { | ||
| String name = "builderDimension"; | ||
| Mapper.Builder mockBuilder = mock(Mapper.Builder.class); | ||
| when(mockBuilder.getSupportedDataCubeDimensionType()).thenReturn(java.util.Optional.of(DimensionType.KEYWORD)); | ||
|
|
||
| Dimension dimension = DimensionFactory.parseAndCreateDimension(name, mockBuilder, new HashMap<>(), null); | ||
|
|
||
| assertTrue(dimension instanceof KeywordDimension); | ||
| assertEquals(name, dimension.getField()); | ||
| } | ||
|
|
||
| public void testParseAndCreateDimensionWithUnsupportedBuilder() { | ||
| String name = "unsupportedBuilderDimension"; | ||
| Mapper.Builder mockBuilder = mock(Mapper.Builder.class); | ||
| when(mockBuilder.getSupportedDataCubeDimensionType()).thenReturn(java.util.Optional.empty()); | ||
|
|
||
| IllegalArgumentException exception = expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> DimensionFactory.parseAndCreateDimension(name, mockBuilder, new HashMap<>(), null) | ||
| ); | ||
| assertTrue(exception.getMessage().contains("unsupported field type")); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.