Skip to content

Commit

Permalink
Rename valueCount() to entryValueCount()
Browse files Browse the repository at this point in the history
Signed-off-by: Sandesh Kumar <[email protected]>
  • Loading branch information
sandeshkr419 committed Oct 21, 2024
1 parent 1c74afb commit baecc1c
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class FeatureFlags {
* aggregations.
*/
public static final String STAR_TREE_INDEX = "opensearch.experimental.feature.composite_index.star_tree.enabled";
public static final Setting<Boolean> STAR_TREE_INDEX_SETTING = Setting.boolSetting(STAR_TREE_INDEX, false, Property.NodeScope);
public static final Setting<Boolean> STAR_TREE_INDEX_SETTING = Setting.boolSetting(STAR_TREE_INDEX, true, Property.NodeScope);

/**
* Gates the functionality of application based configuration templates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static LeafBucketCollector getStarTreeLeafCollector(
}

// Iterate over the values for the current entryId
for (int i = 0, count = valuesIterator.valuesCount(); i < count; i++) {
for (int i = 0, count = valuesIterator.entryValueCount(); i < count; i++) {
long value = valuesIterator.nextValue();
valueConsumer.accept(value); // Apply the consumer operation (e.g., max, sum)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public long nextValue() throws IOException {
return ((SortedNumericDocValues) docIdSetIterator).nextValue();
}

public int valuesCount() throws IOException {
public int entryValueCount() throws IOException {
return ((SortedNumericDocValues) docIdSetIterator).docValueCount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public LeafBucketCollector getStarTreeLeafCollector(LeafReaderContext ctx, LeafB
}

// Iterate over the values for the current entryId
for (int i = 0; i < sumValuesIterator.valuesCount(); i++) {
for (int i = 0; i < sumValuesIterator.entryValueCount(); i++) {
kahanSummation.add(NumericUtils.sortableLongToDouble(sumValuesIterator.nextValue()));
counts.increment(0, countValueIterator.nextValue()); // Apply the consumer operation (e.g., max, sum)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static FixedBitSet getStarTreeResult(StarTreeValues starTreeValues, Map<S
? bitSet.nextSetBit(entryId + 1)
: DocIdSetIterator.NO_MORE_DOCS) {
if (ndv.advance(entryId) != StarTreeValuesIterator.NO_MORE_ENTRIES) {
final int valuesCount = ndv.valuesCount();
final int valuesCount = ndv.entryValueCount();
for (int i = 0; i < valuesCount; i++) {
long value = ndv.nextValue();
// Compare the value with the query value
Expand Down Expand Up @@ -207,7 +207,7 @@ private static StarTreeResult traverseStarTree(StarTreeValues starTreeValues, Ma
/**
* Helper class to wrap the result from traversing the star tree.
* */
public static class StarTreeResult {
private static class StarTreeResult {
public final DocIdSetBuilder matchedDocIds;
public final Set<String> remainingPredicateColumns;
public final int numOfMatchedDocs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ public void setStarTreeValues(LeafReaderContext ctx, FixedBitSet values) {
starTreeValues[ctx.ord] = values;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ private void assertStarTreeContext(
SearchContext context = searchService.createContext(reader, request, null, true);
StarTreeQueryContext actualContext = context.getStarTreeQueryContext();



if (expectedContext == null) {
assertThat(context.getStarTreeQueryContext(), nullValue());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private long getDocCountFromStarTree(CompositeIndexReader starTreeDocValuesReade
assert canAdvance : "Cannot advance to document ID " + bit + " in values iterator.";

// Iterate over values for the current document ID
for (int i = 0, count = valuesIterator.valuesCount(); i < count; i++) {
for (int i = 0, count = valuesIterator.entryValueCount(); i < count; i++) {
long value = valuesIterator.nextValue();
// Assert that the value is as expected using the provided consumer
docCount += value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* 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.search.aggregations.startree;

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.util.FixedBitSet;
import org.junit.Before;
import org.junit.Test;
import org.opensearch.index.codec.composite.CompositeIndexFieldInfo;
import org.opensearch.search.startree.StarTreeQueryContext;
import org.opensearch.test.OpenSearchTestCase;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class StarTreeQueryContextTests extends OpenSearchTestCase {

private CompositeIndexFieldInfo mockStarTree;
private LeafReaderContext mockLeafReaderContext;
private StarTreeQueryContext context;
private Map<String, Long> queryMap;

@Before
public void setUp() {
// Mock dependencies
mockStarTree = mock(CompositeIndexFieldInfo.class);
mockLeafReaderContext = mock(LeafReaderContext.class);

// Prepare queryMap
queryMap = new HashMap<>();
queryMap.put("field1", 123L);
queryMap.put("field2", 456L);

// Simulate leaf reader context ord
when(mockLeafReaderContext.ord).thenReturn(1);
}


public void testConstructorWithValidNumSegmentsCache() {
// Initialize context with valid numSegmentsCache
int numSegmentsCache = 3;
context = new StarTreeQueryContext(mockStarTree, queryMap, numSegmentsCache);

// Verify that the star tree and query map are set correctly
assertEquals(mockStarTree, context.getStarTree());
assertEquals(queryMap, context.getQueryMap());

// Verify that the starTreeValues array is initialized correctly
assertNotNull(context.getStarTreeValues());
assertEquals(numSegmentsCache, context.getStarTreeValues().length);
}


public void testConstructorWithNegativeNumSegmentsCache() {
// Initialize context with invalid numSegmentsCache (-1)
context = new StarTreeQueryContext(mockStarTree, queryMap, -1);

// Verify that the starTreeValues array is not initialized
assertNull(context.getStarTreeValues());
}


public void testGetStarTreeValues_WithValidContext() {
// Initialize context with a cache of size 3
context = new StarTreeQueryContext(mockStarTree, queryMap, 3);

// Create a FixedBitSet and assign it to the context
FixedBitSet fixedBitSet = new FixedBitSet(10);
context.setStarTreeValues(mockLeafReaderContext, fixedBitSet);

// Retrieve the FixedBitSet for the given context
FixedBitSet result = context.getStarTreeValues(mockLeafReaderContext);

// Verify that the correct FixedBitSet is returned
assertNotNull(result);
assertEquals(fixedBitSet, result);
}


public void testGetStarTreeValues_WithNullCache() {
// Initialize context with no cache (numSegmentsCache is -1)
context = new StarTreeQueryContext(mockStarTree, queryMap, -1);

// Retrieve the FixedBitSet for the given context
FixedBitSet result = context.getStarTreeValues(mockLeafReaderContext);

// Verify that the result is null since there's no cache
assertNull(result);
}

public void testSetStarTreeValues() {
// Initialize context with a cache of size 3
context = new StarTreeQueryContext(mockStarTree, queryMap, 3);

// Create a FixedBitSet and assign it to the context
FixedBitSet fixedBitSet = new FixedBitSet(10);
context.setStarTreeValues(mockLeafReaderContext, fixedBitSet);

// Retrieve the FixedBitSet for the given context and verify the update
FixedBitSet result = context.getStarTreeValues(mockLeafReaderContext);
assertEquals(fixedBitSet, result);
}

public void testSetStarTreeValues_WithNullCache() {
// Initialize context with no cache (numSegmentsCache is -1)
context = new StarTreeQueryContext(mockStarTree, queryMap, -1);

// Try setting a FixedBitSet and ensure no exception is thrown
FixedBitSet fixedBitSet = new FixedBitSet(10);
context.setStarTreeValues(mockLeafReaderContext, fixedBitSet);

// Since the cache is null, getStarTreeValues should return null
assertNull(context.getStarTreeValues(mockLeafReaderContext));
}
}

0 comments on commit baecc1c

Please sign in to comment.