Skip to content

Commit 8d27f50

Browse files
addressing comments
Signed-off-by: Sarthak Aggarwal <[email protected]>
1 parent ea7a0d4 commit 8d27f50

File tree

6 files changed

+11
-113
lines changed

6 files changed

+11
-113
lines changed

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/StarTreeTestUtils.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/AbstractValueAggregatorTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

13-
import org.opensearch.index.compositeindex.datacube.startree.StarTreeTestUtils;
1413
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType;
1514
import org.opensearch.test.OpenSearchTestCase;
1615
import org.junit.Before;
@@ -70,7 +69,7 @@ public void testGetInitialAggregatedValueForSegmentDocValue() {
7069
assertEquals(CountValueAggregator.DEFAULT_INITIAL_VALUE, aggregator.getInitialAggregatedValueForSegmentDocValue(randomLong()));
7170
} else {
7271
assertEquals(
73-
StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType),
72+
starTreeNumericType.getDoubleValue(randomLong),
7473
aggregator.getInitialAggregatedValueForSegmentDocValue(randomLong)
7574
);
7675
}

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MaxValueAggregatorTests.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.opensearch.index.compositeindex.datacube.startree.aggregators;
1010

1111
import org.apache.lucene.util.NumericUtils;
12-
import org.opensearch.index.compositeindex.datacube.startree.StarTreeTestUtils;
1312
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType;
1413

1514
public class MaxValueAggregatorTests extends AbstractValueAggregatorTests {
@@ -24,21 +23,13 @@ public void testMergeAggregatedValueAndSegmentValue() {
2423
Long randomLong = randomLong();
2524
double randomDouble = randomDouble();
2625
assertEquals(
27-
Math.max(StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType), randomDouble),
26+
Math.max(starTreeNumericType.getDoubleValue(randomLong), randomDouble),
2827
aggregator.mergeAggregatedValueAndSegmentValue(randomDouble, randomLong),
2928
0.0
3029
);
31-
assertEquals(
32-
StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType),
33-
aggregator.mergeAggregatedValueAndSegmentValue(null, randomLong),
34-
0.0
35-
);
30+
assertEquals(starTreeNumericType.getDoubleValue(randomLong), aggregator.mergeAggregatedValueAndSegmentValue(null, randomLong), 0.0);
3631
assertEquals(randomDouble, aggregator.mergeAggregatedValueAndSegmentValue(randomDouble, null), 0.0);
37-
assertEquals(
38-
Math.max(2.0, StarTreeTestUtils.toStarTreeNumericTypeValue(3L, starTreeNumericType)),
39-
aggregator.mergeAggregatedValueAndSegmentValue(2.0, 3L),
40-
0.0
41-
);
32+
assertEquals(Math.max(2.0, starTreeNumericType.getDoubleValue(3L)), aggregator.mergeAggregatedValueAndSegmentValue(2.0, 3L), 0.0);
4233
}
4334

4435
public void testMergeAggregatedValues() {

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MinValueAggregatorTests.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.opensearch.index.compositeindex.datacube.startree.aggregators;
1010

1111
import org.apache.lucene.util.NumericUtils;
12-
import org.opensearch.index.compositeindex.datacube.startree.StarTreeTestUtils;
1312
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType;
1413

1514
public class MinValueAggregatorTests extends AbstractValueAggregatorTests {
@@ -23,21 +22,13 @@ public void testMergeAggregatedValueAndSegmentValue() {
2322
Long randomLong = randomLong();
2423
double randomDouble = randomDouble();
2524
assertEquals(
26-
Math.min(StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType), randomDouble),
25+
Math.min(starTreeNumericType.getDoubleValue(randomLong), randomDouble),
2726
aggregator.mergeAggregatedValueAndSegmentValue(randomDouble, randomLong),
2827
0.0
2928
);
30-
assertEquals(
31-
StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType),
32-
aggregator.mergeAggregatedValueAndSegmentValue(null, randomLong),
33-
0.0
34-
);
29+
assertEquals(starTreeNumericType.getDoubleValue(randomLong), aggregator.mergeAggregatedValueAndSegmentValue(null, randomLong), 0.0);
3530
assertEquals(randomDouble, aggregator.mergeAggregatedValueAndSegmentValue(randomDouble, null), 0.0);
36-
assertEquals(
37-
Math.min(2.0, StarTreeTestUtils.toStarTreeNumericTypeValue(3L, starTreeNumericType)),
38-
aggregator.mergeAggregatedValueAndSegmentValue(2.0, 3L),
39-
0.0
40-
);
31+
assertEquals(Math.min(2.0, starTreeNumericType.getDoubleValue(3L)), aggregator.mergeAggregatedValueAndSegmentValue(2.0, 3L), 0.0);
4132
}
4233

4334
public void testMergeAggregatedValues() {

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/SumValueAggregatorTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.opensearch.index.compositeindex.datacube.startree.aggregators;
1010

11-
import org.opensearch.index.compositeindex.datacube.startree.StarTreeTestUtils;
1211
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType;
1312

1413
public class SumValueAggregatorTests extends AbstractValueAggregatorTests {
@@ -30,7 +29,7 @@ public void testMergeAggregatedValueAndSegmentValue() {
3029
Long randomLong = randomLong();
3130
aggregator.getInitialAggregatedValue(randomDouble);
3231
assertEquals(
33-
randomDouble + StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType),
32+
randomDouble + starTreeNumericType.getDoubleValue(randomLong),
3433
aggregator.mergeAggregatedValueAndSegmentValue(randomDouble, randomLong),
3534
0.0
3635
);
@@ -42,7 +41,7 @@ public void testMergeAggregatedValueAndSegmentValue_nullSegmentDocValue() {
4241
aggregator.getInitialAggregatedValue(randomDouble1);
4342
assertEquals(randomDouble1, aggregator.mergeAggregatedValueAndSegmentValue(randomDouble1, null), 0.0);
4443
assertEquals(
45-
randomDouble1 + StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType),
44+
randomDouble1 + starTreeNumericType.getDoubleValue(randomLong),
4645
aggregator.mergeAggregatedValueAndSegmentValue(randomDouble1, randomLong),
4746
0.0
4847
);
@@ -51,11 +50,7 @@ public void testMergeAggregatedValueAndSegmentValue_nullSegmentDocValue() {
5150
public void testMergeAggregatedValueAndSegmentValue_nullInitialDocValue() {
5251
Long randomLong = randomLong();
5352
aggregator.getInitialAggregatedValue(null);
54-
assertEquals(
55-
StarTreeTestUtils.toStarTreeNumericTypeValue(randomLong, starTreeNumericType),
56-
aggregator.mergeAggregatedValueAndSegmentValue(null, randomLong),
57-
0.0
58-
);
53+
assertEquals(starTreeNumericType.getDoubleValue(randomLong), aggregator.mergeAggregatedValueAndSegmentValue(null, randomLong), 0.0);
5954
}
6055

6156
public void testMergeAggregatedValues() {

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/builder/AbstractStarTreeBuilderTests.java

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,22 +1509,6 @@ private static StarTreeField getStarTreeFieldWithMultipleMetrics() {
15091509
}
15101510

15111511
public void testMergeFlowWithSum_randomNumberTypes() throws IOException {
1512-
List<Long> dimList = List.of(0L, 1L, 3L, 4L, 5L, 6L);
1513-
List<Integer> docsWithField = List.of(0, 1, 3, 4, 5, 6);
1514-
List<Long> dimList2 = List.of(0L, 1L, 2L, 3L, 4L, 5L, -1L);
1515-
List<Integer> docsWithField2 = List.of(0, 1, 2, 3, 4, 5, 6);
1516-
1517-
List<Long> metricsList = List.of(
1518-
getLongFromDouble(0.0),
1519-
getLongFromDouble(10.0),
1520-
getLongFromDouble(20.0),
1521-
getLongFromDouble(30.0),
1522-
getLongFromDouble(40.0),
1523-
getLongFromDouble(50.0),
1524-
getLongFromDouble(60.0)
1525-
1526-
);
1527-
List<Integer> metricsWithField = List.of(0, 1, 2, 3, 4, 5, 6);
15281512

15291513
DocumentMapper documentMapper = mock(DocumentMapper.class);
15301514
when(mapperService.documentMapper()).thenReturn(documentMapper);
@@ -1555,48 +1539,8 @@ public void testMergeFlowWithSum_randomNumberTypes() throws IOException {
15551539
null
15561540
);
15571541
when(documentMapper.mappers()).thenReturn(fieldMappers);
1542+
testMergeFlowWithSum();
15581543

1559-
StarTreeField sf = getStarTreeField(MetricStat.SUM);
1560-
StarTreeValues starTreeValues = getStarTreeValues(
1561-
getSortedNumericMock(dimList, docsWithField),
1562-
getSortedNumericMock(dimList2, docsWithField2),
1563-
getSortedNumericMock(metricsList, metricsWithField),
1564-
sf,
1565-
"6"
1566-
);
1567-
1568-
StarTreeValues starTreeValues2 = getStarTreeValues(
1569-
getSortedNumericMock(dimList, docsWithField),
1570-
getSortedNumericMock(dimList2, docsWithField2),
1571-
getSortedNumericMock(metricsList, metricsWithField),
1572-
sf,
1573-
"6"
1574-
);
1575-
builder = getStarTreeBuilder(sf, getWriteState(6), mapperService);
1576-
Iterator<StarTreeDocument> starTreeDocumentIterator = builder.mergeStarTrees(List.of(starTreeValues, starTreeValues2));
1577-
/**
1578-
* Asserting following dim / metrics [ dim1, dim2 / Sum [ metric] ]
1579-
* [0, 0] | [0.0]
1580-
* [1, 1] | [20.0]
1581-
* [3, 3] | [60.0]
1582-
* [4, 4] | [80.0]
1583-
* [5, 5] | [100.0]
1584-
* [null, 2] | [40.0]
1585-
* ------------------ We only take non star docs
1586-
* [6,-1] | [120.0]
1587-
*/
1588-
int count = 0;
1589-
while (starTreeDocumentIterator.hasNext()) {
1590-
count++;
1591-
StarTreeDocument starTreeDocument = starTreeDocumentIterator.next();
1592-
assertEquals(
1593-
starTreeDocument.dimensions[0] != null ? starTreeDocument.dimensions[0] * 2 * 10.0 : 40.0,
1594-
starTreeDocument.metrics[0]
1595-
);
1596-
}
1597-
assertEquals(6, count);
1598-
builder.build(starTreeDocumentIterator);
1599-
validateStarTree(builder.getRootNode(), 2, 1, builder.getStarTreeDocuments());
16001544
}
16011545

16021546
public void testMergeFlowWithSum() throws IOException {

0 commit comments

Comments
 (0)