-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Star tree] Support for keyword changes as part of star tree mapper #16103
Draft
bharath-techie
wants to merge
13
commits into
opensearch-project:main
Choose a base branch
from
bharath-techie:keyword-mapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3f82b5a
Adding timestamp rounding support in star tree
bharath-techie fc9614f
adding half hour and quarter hour calendar intervals
bharath-techie da9b146
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 014f123
adding tests
bharath-techie 0b4bfb2
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 221aee6
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 078aafa
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie a52b29c
resolving conflicts
bharath-techie 4387345
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 7243dd1
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 9a4e7f3
Adding support for date dim and adding back tests resolving conflicts
bharath-techie eb43e37
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 49dd2f5
star tree keyword changes
bharath-techie 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 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 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import org.apache.lucene.index.SegmentInfo; | ||
import org.apache.lucene.index.SegmentWriteState; | ||
import org.apache.lucene.index.SortedNumericDocValues; | ||
import org.apache.lucene.index.SortedSetDocValues; | ||
import org.apache.lucene.search.DocIdSetIterator; | ||
import org.apache.lucene.store.IndexOutput; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
|
@@ -34,6 +35,7 @@ | |
import org.opensearch.index.compositeindex.datacube.startree.index.StarTreeValues; | ||
import org.opensearch.index.mapper.CompositeMappedFieldType; | ||
import org.opensearch.index.mapper.DocCountFieldMapper; | ||
import org.opensearch.index.mapper.KeywordFieldMapper; | ||
import org.opensearch.index.mapper.MapperService; | ||
import org.opensearch.index.mapper.StarTreeMapper; | ||
|
||
|
@@ -82,14 +84,7 @@ public Composite99DocValuesWriter(DocValuesConsumer delegate, SegmentWriteState | |
this.compositeMappedFieldTypes = mapperService.getCompositeFieldTypes(); | ||
compositeFieldSet = new HashSet<>(); | ||
segmentFieldSet = new HashSet<>(); | ||
// TODO : add integ test for this | ||
for (FieldInfo fi : this.state.fieldInfos) { | ||
if (DocValuesType.SORTED_NUMERIC.equals(fi.getDocValuesType())) { | ||
segmentFieldSet.add(fi.name); | ||
} else if (fi.name.equals(DocCountFieldMapper.NAME)) { | ||
segmentFieldSet.add(fi.name); | ||
} | ||
} | ||
addStarTreeSupportedFieldsFromSegment(); | ||
for (CompositeMappedFieldType type : compositeMappedFieldTypes) { | ||
compositeFieldSet.addAll(type.fields()); | ||
} | ||
|
@@ -148,6 +143,19 @@ public Composite99DocValuesWriter(DocValuesConsumer delegate, SegmentWriteState | |
segmentHasCompositeFields = Collections.disjoint(segmentFieldSet, compositeFieldSet) == false; | ||
} | ||
|
||
private void addStarTreeSupportedFieldsFromSegment() { | ||
// TODO : add integ test for this | ||
for (FieldInfo fi : this.state.fieldInfos) { | ||
if (DocValuesType.SORTED_NUMERIC.equals(fi.getDocValuesType())) { | ||
segmentFieldSet.add(fi.name); | ||
} else if (DocValuesType.SORTED_SET.equals(fi.getDocValuesType())) { | ||
segmentFieldSet.add(fi.name); | ||
} else if (fi.name.equals(DocCountFieldMapper.NAME)) { | ||
segmentFieldSet.add(fi.name); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void addNumericField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException { | ||
delegate.addNumericField(field, valuesProducer); | ||
|
@@ -179,6 +187,10 @@ public void addSortedNumericField(FieldInfo field, DocValuesProducer valuesProdu | |
@Override | ||
public void addSortedSetField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException { | ||
delegate.addSortedSetField(field, valuesProducer); | ||
// Perform this only during flush flow | ||
if (mergeState.get() == null && segmentHasCompositeFields) { | ||
createCompositeIndicesIfPossible(valuesProducer, field); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -235,6 +247,7 @@ private void createCompositeIndicesIfPossible(DocValuesProducer valuesProducer, | |
* Add empty doc values for fields not present in segment | ||
*/ | ||
private void addDocValuesForEmptyField(String compositeField) { | ||
// special case for doc count | ||
if (compositeField.equals(DocCountFieldMapper.NAME)) { | ||
fieldProducerMap.put(compositeField, new EmptyDocValuesProducer() { | ||
@Override | ||
|
@@ -243,16 +256,29 @@ public NumericDocValues getNumeric(FieldInfo field) { | |
} | ||
}); | ||
} else { | ||
fieldProducerMap.put(compositeField, new EmptyDocValuesProducer() { | ||
@Override | ||
public SortedNumericDocValues getSortedNumeric(FieldInfo field) { | ||
return DocValues.emptySortedNumeric(); | ||
} | ||
}); | ||
if(isSortedSetField(compositeField)) { | ||
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. should we have a switch? for when we support more field types. |
||
fieldProducerMap.put(compositeField, new EmptyDocValuesProducer() { | ||
@Override | ||
public SortedSetDocValues getSortedSet(FieldInfo field) { | ||
return DocValues.emptySortedSet(); | ||
} | ||
}); | ||
} else { | ||
fieldProducerMap.put(compositeField, new EmptyDocValuesProducer() { | ||
@Override | ||
public SortedNumericDocValues getSortedNumeric(FieldInfo field) { | ||
return DocValues.emptySortedNumeric(); | ||
} | ||
}); | ||
} | ||
} | ||
compositeFieldSet.remove(compositeField); | ||
} | ||
|
||
private boolean isSortedSetField(String field) { | ||
return mapperService.fieldType(field) instanceof KeywordFieldMapper.KeywordFieldType; | ||
} | ||
|
||
@Override | ||
public void merge(MergeState mergeState) throws IOException { | ||
this.mergeState.compareAndSet(null, mergeState); | ||
|
This file contains 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 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 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; | ||
|
||
/** | ||
* 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 int setDimensionValues(Long value, Long[] dims, int index) { | ||
dims[index++] = value; | ||
return index; | ||
} | ||
|
||
@Override | ||
public List<String> getDimensionFieldsNames() { | ||
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); | ||
} | ||
} |
This file contains 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 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 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.
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 are we returning "ip" in the above two ifs?