Skip to content

Commit

Permalink
rename count to value_count (#15147) (#15408)
Browse files Browse the repository at this point in the history
(cherry picked from commit e8ee6db)

Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 178a78c commit 042a563
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testValidCompositeIndex() {
assertEquals("numeric_dv", starTreeFieldType.getMetrics().get(0).getField());
List<MetricStat> expectedMetrics = Arrays.asList(
MetricStat.AVG,
MetricStat.COUNT,
MetricStat.VALUE_COUNT,
MetricStat.SUM,
MetricStat.MAX,
MetricStat.MIN
Expand Down Expand Up @@ -351,7 +351,7 @@ public void testUpdateIndexWhenMappingIsSame() {
assertEquals("numeric_dv", starTreeFieldType.getMetrics().get(0).getField());
List<MetricStat> expectedMetrics = Arrays.asList(
MetricStat.AVG,
MetricStat.COUNT,
MetricStat.VALUE_COUNT,
MetricStat.SUM,
MetricStat.MAX,
MetricStat.MIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
@ExperimentalApi
public enum MetricStat {
COUNT("count"),
VALUE_COUNT("value_count"),
AVG("avg"),
SUM("sum"),
MIN("min"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class StarTreeIndexSettings {
"index.composite_index.star_tree.field.default.metrics",
Arrays.asList(
MetricStat.AVG.toString(),
MetricStat.COUNT.toString(),
MetricStat.VALUE_COUNT.toString(),
MetricStat.SUM.toString(),
MetricStat.MAX.toString(),
MetricStat.MIN.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static ValueAggregator getValueAggregator(MetricStat aggregationType, Sta
// avg aggregator will be covered in the part of query (using count and sum)
case SUM:
return new SumValueAggregator(starTreeNumericType);
case COUNT:
case VALUE_COUNT:
return new CountValueAggregator(starTreeNumericType);
case MIN:
return new MinValueAggregator(starTreeNumericType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.common.util;

import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.RandomAccessInput;
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.nio.file.Path;

/**
* Tests for {@link ByteArrayBackedBitset}
*/
public class ByteArrayBackedBitsetTests extends OpenSearchTestCase {
public void testWriteAndReadNullBitSets() throws IOException {
for (int k = 0; k < 10; k++) {
int randomArraySize = randomIntBetween(2, 300);
int randomIndex1 = randomIntBetween(0, (randomArraySize - 1) * 8);
int randomIndex2 = randomIntBetween(0, (randomArraySize - 1) * 8);
testWriteAndReadBitset(randomArraySize, randomIndex1, randomIndex2);
}
}

private static void testWriteAndReadBitset(int randomArraySize, int randomIndex1, int randomIndex2) throws IOException {
ByteArrayBackedBitset bitset = new ByteArrayBackedBitset(randomArraySize);
Path basePath = createTempDir("OffHeapTests");
FSDirectory fsDirectory = FSDirectory.open(basePath);
String TEST_FILE = "test_file";
IndexOutput indexOutput = fsDirectory.createOutput(TEST_FILE, IOContext.DEFAULT);
bitset.set(randomIndex1);
bitset.set(randomIndex2);
bitset.write(indexOutput);
indexOutput.close();

IndexInput in = fsDirectory.openInput(TEST_FILE, IOContext.DEFAULT);
RandomAccessInput randomAccessInput = in.randomAccessSlice(0, in.length());
ByteArrayBackedBitset bitset1 = new ByteArrayBackedBitset(randomAccessInput, 0, randomArraySize);
for (int i = 0; i < (randomArraySize * 8); i++) {
if (randomIndex1 == i || randomIndex2 == i) {
assertTrue(bitset1.get(i));
} else {
assertFalse(bitset1.get(i));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private XContentBuilder getExpandedMapping(String dim, String metric) throws IOE
b.field("name", "field");
b.startArray("stats");
b.value("sum");
b.value("count"); // TODO : THIS TEST FAILS.
b.value("value_count");
b.endArray();
b.endObject();
b.endArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public void testConstructor() {

public void testCountStarConstructor() {
MetricAggregatorInfo pair = new MetricAggregatorInfo(
MetricStat.COUNT,
MetricStat.VALUE_COUNT,
"anything",
"star_tree_field",
IndexNumericFieldData.NumericType.DOUBLE
);
assertEquals(MetricStat.COUNT, pair.getMetricStat());
assertEquals(MetricStat.VALUE_COUNT, pair.getMetricStat());
assertEquals("anything", pair.getField());
}

Expand Down Expand Up @@ -62,7 +62,7 @@ public void testEquals() {
assertEquals(pair1, pair2);
assertNotEquals(
pair1,
new MetricAggregatorInfo(MetricStat.COUNT, "column1", "star_tree_field", IndexNumericFieldData.NumericType.DOUBLE)
new MetricAggregatorInfo(MetricStat.VALUE_COUNT, "column1", "star_tree_field", IndexNumericFieldData.NumericType.DOUBLE)
);
assertNotEquals(
pair1,
Expand Down Expand Up @@ -100,7 +100,7 @@ public void testCompareTo() {
IndexNumericFieldData.NumericType.DOUBLE
);
MetricAggregatorInfo pair3 = new MetricAggregatorInfo(
MetricStat.COUNT,
MetricStat.VALUE_COUNT,
"column1",
"star_tree_field",
IndexNumericFieldData.NumericType.DOUBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testGetValueAggregatorForMaxType() {
}

public void testGetValueAggregatorForCountType() {
ValueAggregator aggregator = ValueAggregatorFactory.getValueAggregator(MetricStat.COUNT, StarTreeNumericType.LONG);
ValueAggregator aggregator = ValueAggregatorFactory.getValueAggregator(MetricStat.VALUE_COUNT, StarTreeNumericType.LONG);
assertNotNull(aggregator);
assertEquals(CountValueAggregator.class, aggregator.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void setup() throws IOException {
metrics = List.of(
new Metric("field2", List.of(MetricStat.SUM)),
new Metric("field4", List.of(MetricStat.SUM)),
new Metric("field6", List.of(MetricStat.COUNT)),
new Metric("field6", List.of(MetricStat.VALUE_COUNT)),
new Metric("field9", List.of(MetricStat.MIN)),
new Metric("field10", List.of(MetricStat.MAX))
);
Expand Down Expand Up @@ -1496,7 +1496,7 @@ private static StarTreeField getStarTreeFieldWithMultipleMetrics() {
Dimension d1 = new NumericDimension("field1");
Dimension d2 = new NumericDimension("field3");
Metric m1 = new Metric("field2", List.of(MetricStat.SUM));
Metric m2 = new Metric("field2", List.of(MetricStat.COUNT));
Metric m2 = new Metric("field2", List.of(MetricStat.VALUE_COUNT));
List<Dimension> dims = List.of(d1, d2);
List<Metric> metrics = List.of(m1, m2);
StarTreeFieldConfiguration c = new StarTreeFieldConfiguration(
Expand Down Expand Up @@ -1578,7 +1578,7 @@ public void testMergeFlowWithCount() throws IOException {
List<Long> metricsList = List.of(0L, 1L, 2L, 3L, 4L, 5L, 6L);
List<Integer> metricsWithField = List.of(0, 1, 2, 3, 4, 5, 6);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -1658,7 +1658,7 @@ public void testMergeFlowWithDifferentDocsFromSegments() throws IOException {
List<Long> metricsList2 = List.of(5L, 6L, 7L, 8L, 9L);
List<Integer> metricsWithField2 = List.of(0, 1, 2, 3, 4);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -1720,7 +1720,7 @@ public void testMergeFlowNumSegmentsDocs() throws IOException {
List<Long> metricsList2 = List.of(5L, 6L, 7L, 8L, 9L);
List<Integer> metricsWithField2 = List.of(0, 1, 2, 3, 4);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -1780,7 +1780,7 @@ public void testMergeFlowWithMissingDocs() throws IOException {
List<Long> metricsList2 = List.of(5L, 6L, 7L, 8L, 9L);
List<Integer> metricsWithField2 = List.of(0, 1, 2, 3, 4);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -1842,7 +1842,7 @@ public void testMergeFlowWithMissingDocsWithZero() throws IOException {
List<Long> metricsList2 = List.of(5L, 6L, 7L, 8L, 9L);
List<Integer> metricsWithField2 = List.of(0, 1, 2, 3, 4);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -1905,7 +1905,7 @@ public void testMergeFlowWithMissingDocsWithZeroComplexCase() throws IOException
List<Long> metricsList2 = List.of(5L, 6L, 7L, 8L, 9L);
List<Integer> metricsWithField2 = List.of(0, 1, 2, 3, 4);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -1972,7 +1972,7 @@ public void testMergeFlowWithMissingDocsInSecondDim() throws IOException {
List<Long> metricsList2 = List.of(5L, 6L, 7L, 8L, 9L);
List<Integer> metricsWithField2 = List.of(0, 1, 2, 3, 4);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -2035,7 +2035,7 @@ public void testMergeFlowWithDocsMissingAtTheEnd() throws IOException {
List<Long> metricsList2 = List.of(5L, 6L, 7L, 8L, 9L);
List<Integer> metricsWithField2 = List.of(0, 1, 2, 3, 4);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down Expand Up @@ -2089,7 +2089,7 @@ public void testMergeFlowWithEmptyFieldsInOneSegment() throws IOException {
List<Long> metricsList = List.of(0L, 1L, 2L, 3L, 4L, 5L, 6L);
List<Integer> metricsWithField = List.of(0, 1, 2, 3, 4, 5, 6);

StarTreeField sf = getStarTreeField(MetricStat.COUNT);
StarTreeField sf = getStarTreeField(MetricStat.VALUE_COUNT);
StarTreeValues starTreeValues = getStarTreeValues(
getSortedNumericMock(dimList, docsWithField),
getSortedNumericMock(dimList2, docsWithField2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testValidStarTreeDefaults() throws IOException {
assertEquals("status", starTreeFieldType.getMetrics().get(0).getField());
List<MetricStat> expectedMetrics = Arrays.asList(
MetricStat.AVG,
MetricStat.COUNT,
MetricStat.VALUE_COUNT,
MetricStat.SUM,
MetricStat.MAX,
MetricStat.MIN
Expand Down Expand Up @@ -223,11 +223,11 @@ public void testMetric() {
assertEquals(metric1, metric2);
List<MetricStat> m2 = new ArrayList<>();
m2.add(MetricStat.MAX);
m2.add(MetricStat.COUNT);
m2.add(MetricStat.VALUE_COUNT);
metric2 = new Metric("name", m2);
assertNotEquals(metric1, metric2);

assertEquals(MetricStat.COUNT, MetricStat.fromTypeName("count"));
assertEquals(MetricStat.VALUE_COUNT, MetricStat.fromTypeName("value_count"));
assertEquals(MetricStat.MAX, MetricStat.fromTypeName("max"));
assertEquals(MetricStat.MIN, MetricStat.fromTypeName("min"));
assertEquals(MetricStat.SUM, MetricStat.fromTypeName("sum"));
Expand Down

0 comments on commit 042a563

Please sign in to comment.