Skip to content

Commit 8f9477a

Browse files
committed
Using advanceExact instead of advance due to AssertionError at IndexedDISI
Signed-off-by: expani <anijainc@amazon.com>
1 parent 1ce6ed0 commit 8f9477a

File tree

6 files changed

+23
-34
lines changed

6 files changed

+23
-34
lines changed

server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/iterator/SortedSetStarTreeValuesIterator.java

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public long value() throws IOException {
3434
return nextOrd();
3535
}
3636

37+
@Override
38+
public boolean advanceExact(int target) throws IOException {
39+
return ((SortedSetDocValues) docIdSetIterator).advanceExact(target);
40+
}
41+
3742
public long nextOrd() throws IOException {
3843
return ((SortedSetDocValues) docIdSetIterator).nextOrd();
3944
}

server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/iterator/StarTreeValuesIterator.java

+2
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ public long cost() {
4848

4949
public abstract long value() throws IOException;
5050

51+
public abstract boolean advanceExact(int target) throws IOException;
52+
5153
}

server/src/main/java/org/opensearch/search/startree/StarTreeTraversalUtil.java

+1-29
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.opensearch.index.compositeindex.datacube.startree.node.StarTreeNode;
1919
import org.opensearch.index.compositeindex.datacube.startree.node.StarTreeNodeType;
2020
import org.opensearch.index.compositeindex.datacube.startree.utils.iterator.SortedNumericStarTreeValuesIterator;
21-
import org.opensearch.index.compositeindex.datacube.startree.utils.iterator.SortedSetStarTreeValuesIterator;
2221
import org.opensearch.index.compositeindex.datacube.startree.utils.iterator.StarTreeValuesIterator;
2322
import org.opensearch.search.internal.SearchContext;
2423
import org.opensearch.search.startree.filter.DimensionFilter;
@@ -58,8 +57,6 @@ public static FixedBitSet getStarTreeResult(StarTreeValues starTreeValues, StarT
5857

5958
StarTreeResult starTreeResult = traverseStarTree(starTreeValues, starTreeFilter);
6059

61-
//iterateOverAllDimensionValues(starTreeValues);
62-
6360
// Initialize FixedBitSet with size maxMatchedDoc + 1
6461
FixedBitSet bitSet = new FixedBitSet(starTreeResult.maxMatchedDoc + 1);
6562
SortedNumericStarTreeValuesIterator starTreeValuesIterator = new SortedNumericStarTreeValuesIterator(
@@ -95,7 +92,7 @@ public static FixedBitSet getStarTreeResult(StarTreeValues starTreeValues, StarT
9592
for (int entryId = bitSet.nextSetBit(0); entryId != DocIdSetIterator.NO_MORE_DOCS; entryId = (entryId + 1 < bitSet.length())
9693
? bitSet.nextSetBit(entryId + 1)
9794
: DocIdSetIterator.NO_MORE_DOCS) {
98-
if (valuesIterator.advance(entryId) != StarTreeValuesIterator.NO_MORE_ENTRIES) {
95+
if (valuesIterator.advanceExact(entryId)) {
9996
long value = valuesIterator.value();
10097
for (DimensionFilter dimensionFilter : dimensionFilters) {
10198
if (dimensionFilter.matchDimValue(value, starTreeValues)) {
@@ -114,31 +111,6 @@ public static FixedBitSet getStarTreeResult(StarTreeValues starTreeValues, StarT
114111
return bitSet; // Return the final FixedBitSet with all matches
115112
}
116113

117-
private static void iterateOverAllDimensionValues(StarTreeValues starTreeValues) throws IOException {
118-
for (String dimensionName : starTreeValues.getStarTreeField().getDimensionNames()) {
119-
StarTreeValuesIterator starTreeValuesIterator = starTreeValues.getDimensionValuesIterator(dimensionName);
120-
int docId = 0;
121-
List<Integer> docIds = new ArrayList<>();
122-
List<Object> values = new ArrayList<>();
123-
while (starTreeValuesIterator.advance(docId) != NO_MORE_DOCS) {
124-
docIds.add(starTreeValuesIterator.entryId());
125-
if (starTreeValuesIterator instanceof SortedNumericStarTreeValuesIterator) {
126-
values.add(((SortedNumericStarTreeValuesIterator) starTreeValuesIterator).nextValue());
127-
} else if (starTreeValuesIterator instanceof SortedSetStarTreeValuesIterator) {
128-
values.add(((SortedSetStarTreeValuesIterator) starTreeValuesIterator).nextOrd());
129-
}
130-
docId++;
131-
}
132-
System.out.printf(
133-
"\n\nDimension Values for dimension %s has size %s and are %s and docIds are %s",
134-
dimensionName,
135-
values.size(),
136-
values,
137-
docIds
138-
);
139-
}
140-
}
141-
142114
private static StarTreeResult traverseStarTree(StarTreeValues starTreeValues, StarTreeFilter starTreeFilter) throws IOException {
143115
DocIdSetBuilder docsWithField = new DocIdSetBuilder(starTreeValues.getStarTreeDocumentCount());
144116
DocIdSetBuilder.BulkAdder adder;

server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ protected Codec getCodec() {
111111
final Logger testLogger = LogManager.getLogger(MetricAggregatorTests.class);
112112
MapperService mapperService;
113113
try {
114+
// FIXME: Test for different max_leaf_docs with at least 1, 2-100, 101-10_000 for all query types
114115
mapperService = StarTreeDocValuesFormatTests.createMapperService(
115116
StarTreeQueryTests.getExpandedMapping(randomIntBetween(1, 10_000), false)
116117
);
@@ -124,6 +125,7 @@ protected Codec getCodec() {
124125
public void testStarTreeDocValues() throws IOException {
125126
Directory directory = newDirectory();
126127
IndexWriterConfig conf = newIndexWriterConfig(null);
128+
// FIXME: Test for different max_leaf_docs with at least 1, 2-100, 101-10_000 for all query types
127129
conf.setCodec(getCodec());
128130
conf.setMergePolicy(newLogMergePolicy());
129131
RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);
@@ -139,6 +141,7 @@ public void testStarTreeDocValues() throws IOException {
139141
// Index 100 random documents
140142
for (int i = 0; i < totalDocs; i++) {
141143
Document doc = new Document();
144+
// FIXME: Reduce the frequency of nulls to be with at least some non-null docs like after every 1-2 ?
142145
if (random.nextBoolean()) {
143146
val = random.nextInt(10) - 5; // Random long between -5 and 4
144147
doc.add(new LongField(SNDV, val, Field.Store.YES));
@@ -174,6 +177,7 @@ public void testStarTreeDocValues() throws IOException {
174177

175178
MapperService mapperService = mapperServiceMock();
176179
CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
180+
// FIXME : Register for other dimensions. Move to a common place where per dimension actions are done ?
177181
when(mapperService.fieldType(SNDV)).thenReturn(new NumberFieldMapper.NumberFieldType(SNDV, NumberFieldMapper.NumberType.LONG));
178182
when(mapperService.fieldType(DV)).thenReturn(new NumberFieldMapper.NumberFieldType(DV, NumberFieldMapper.NumberType.LONG));
179183
when(mapperService.fieldType(KEYWORD)).thenReturn(new KeywordFieldMapper.KeywordFieldType(KEYWORD));
@@ -184,6 +188,7 @@ public void testStarTreeDocValues() throws IOException {
184188
circuitBreakerService,
185189
new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking()
186190
);
191+
// FIXME : Register for other dimensions. Move to a common place where per dimension actions are done ?
187192
when(queryShardContext.fieldMapper(SNDV)).thenReturn(
188193
new NumberFieldMapper.NumberFieldType(SNDV, NumberFieldMapper.NumberType.LONG)
189194
);
@@ -199,17 +204,19 @@ public void testStarTreeDocValues() throws IOException {
199204
ValueCountAggregationBuilder valueCountAggregationBuilder = count("_name").field(FIELD_NAME);
200205
AvgAggregationBuilder avgAggregationBuilder = avg("_name").field(FIELD_NAME);
201206

207+
// FIXME : Add Float, Half Float and Double. Integer/Long whichever is missing
202208
List<Dimension> supportedDimensions = new LinkedList<>();
203209
supportedDimensions.add(new NumericDimension(SNDV));
204210
supportedDimensions.add(new NumericDimension(DV));
205211
supportedDimensions.add(new OrdinalDimension(KEYWORD));
206212

207213
Query query = new MatchAllDocsQuery();
208214
// match-all query
215+
// FIXME : Add support for numeric and keyword terms query
209216
QueryBuilder numericTermQueryBuilder = null; // no predicates
210217
QueryBuilder numericRangeQueryBuilder = null;
211-
QueryBuilder keywordTermQueryBuilder = null;
212-
QueryBuilder keywordRangeQueryBuilder = null;
218+
QueryBuilder keywordTermQueryBuilder;
219+
QueryBuilder keywordRangeQueryBuilder;
213220
testCase(
214221
indexSearcher,
215222
query,
@@ -455,10 +462,10 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void testC
455462
QueryBuilder queryBuilder,
456463
T aggBuilder,
457464
CompositeIndexFieldInfo starTree,
458-
List<Dimension> supportedDimensions,
459-
List<Metric> supportedMetrics,
465+
List<Dimension> supportedDimensions, // FIXME : Merge with the same input that goes to generating the codec.
466+
List<Metric> supportedMetrics, // FIXME : Merge with the same input that goes to generating the codec.
460467
BiConsumer<V, V> verify,
461-
AggregatorFactory aggregatorFactory,
468+
AggregatorFactory aggregatorFactory, // TODO : Recheck if this can be done elsewhere.
462469
boolean assertCollectorEarlyTermination
463470
) throws IOException {
464471
V starTreeAggregation = searchAndReduceStarTree(

server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeQueryTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ public static XContentBuilder getExpandedMapping(int maxLeafDocs, boolean skipSt
357357
b.value("sdv");
358358
b.endArray();
359359
}
360+
// FIXME : Change to take dimension order and other inputs as method params.
361+
// FIXME : Create default constants for the existing so other can call easily.
360362
b.startArray("ordered_dimensions");
361363
b.startObject();
362364
b.field("name", "sndv");

test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java

+1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ protected SearchContext createSearchContextWithStarTreeContext(
431431
when(mapperService.getCompositeFieldTypes()).thenReturn(compositeFieldTypes);
432432
when(searchContext.mapperService()).thenReturn(mapperService);
433433

434+
// FIXME : Directly supply the dimension as method param, we are resetting this again ?
434435
for (Dimension dimension : supportedDimensions) {
435436
if (dimension instanceof OrdinalDimension) {
436437
MappedFieldType mappedFieldType = new KeywordFieldMapper.KeywordFieldType(dimension.getField(), Lucene.WHITESPACE_ANALYZER);

0 commit comments

Comments
 (0)