Skip to content

Commit

Permalink
adding some more tests and fix
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
  • Loading branch information
bharath-techie committed Jun 28, 2024
1 parent ed01cc0 commit b813450
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 1 deletion.
1 change: 0 additions & 1 deletion distribution/src/config/jvm.options
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ ${error.file}

# HDFS ForkJoinPool.common() support by SecurityManager
-Djava.util.concurrent.ForkJoinPool.common.threadFactory=org.opensearch.secure_sm.SecuredForkJoinWorkerThreadFactory
-Dopensearch.experimental.feature.composite_index.star_tree.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.opensearch.index.compositeindex.datacube.DateDimension;
import org.opensearch.index.compositeindex.datacube.MetricStat;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeFieldConfiguration;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeIndexSettings;
import org.opensearch.indices.IndicesService;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.junit.After;
Expand Down Expand Up @@ -89,6 +90,55 @@ private static XContentBuilder createMinimalTestMapping(boolean invalidDim, bool
}
}

private static XContentBuilder createMaxDimTestMapping() {
try {
return jsonBuilder().startObject()
.startObject("composite")
.startObject("startree-1")
.field("type", "star_tree")
.startObject("config")
.startArray("ordered_dimensions")
.startObject()
.field("name", "timestamp")
.startArray("calendar_intervals")
.value("day")
.value("month")
.endArray()
.endObject()
.startObject()
.field("name", "dim2")
.endObject()
.startObject()
.field("name", "dim3")
.endObject()
.endArray()
.startArray("metrics")
.startObject()
.field("name", "dim2")
.endObject()
.endArray()
.endObject()
.endObject()
.endObject()
.startObject("properties")
.startObject("timestamp")
.field("type", "date")
.endObject()
.startObject("dim2")
.field("type", "integer")
.field("doc_values", true)
.endObject()
.startObject("dim3")
.field("type", "integer")
.field("doc_values", true)
.endObject()
.endObject()
.endObject();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}

private static XContentBuilder createTestMappingWithoutStarTree(boolean invalidDim, boolean invalidMetric, boolean keywordDim) {
try {
return jsonBuilder().startObject()
Expand Down Expand Up @@ -329,6 +379,32 @@ public void testInvalidDimCompositeIndex() {
);
}

public void testMaxDimsCompositeIndex() {
MapperParsingException ex = expectThrows(
MapperParsingException.class,
() -> prepareCreate(TEST_INDEX).setMapping(createMaxDimTestMapping())
.setSettings(Settings.builder().put(StarTreeIndexSettings.STAR_TREE_MAX_DIMENSIONS_SETTING.getKey(), 2))
.get()
);
assertEquals(
"Failed to parse mapping [_doc]: ordered_dimensions cannot have more than 2 dimensions for star tree field [startree-1]",
ex.getMessage()
);
}

public void testMaxCalendarIntervalsCompositeIndex() {
MapperParsingException ex = expectThrows(
MapperParsingException.class,
() -> prepareCreate(TEST_INDEX).setMapping(createMaxDimTestMapping())
.setSettings(Settings.builder().put(StarTreeIndexSettings.STAR_TREE_MAX_DATE_INTERVALS_SETTING.getKey(), 1))
.get()
);
assertEquals(
"Failed to parse mapping [_doc]: At most [1] calendar intervals are allowed in dimension [timestamp]",
ex.getMessage()
);
}

public void testUnsupportedDim() {
MapperParsingException ex = expectThrows(
MapperParsingException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.compositeindex.datacube.DateDimension;
import org.opensearch.index.compositeindex.datacube.Dimension;
import org.opensearch.index.compositeindex.datacube.Metric;
import org.opensearch.index.compositeindex.datacube.MetricStat;
import org.opensearch.index.compositeindex.datacube.NumericDimension;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeField;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeFieldConfiguration;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -207,6 +212,100 @@ public void testInvalidSingleDim() {
);
}

public void testMetric() {
List<MetricStat> m1 = new ArrayList<>();
m1.add(MetricStat.MAX);
Metric metric1 = new Metric("name", m1);
Metric metric2 = new Metric("name", m1);
assertEquals(metric1, metric2);
List<MetricStat> m2 = new ArrayList<>();
m2.add(MetricStat.MAX);
m2.add(MetricStat.COUNT);
metric2 = new Metric("name", m2);
assertNotEquals(metric1, metric2);

assertEquals(MetricStat.COUNT, MetricStat.fromTypeName("count"));
assertEquals(MetricStat.MAX, MetricStat.fromTypeName("max"));
assertEquals(MetricStat.MIN, MetricStat.fromTypeName("min"));
assertEquals(MetricStat.SUM, MetricStat.fromTypeName("sum"));
assertEquals(MetricStat.AVG, MetricStat.fromTypeName("avg"));
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> MetricStat.fromTypeName("invalid"));
assertEquals("Invalid metric stat: invalid", ex.getMessage());
}

public void testDimensions() {
List<Rounding.DateTimeUnit> d1CalendarIntervals = new ArrayList<>();
d1CalendarIntervals.add(Rounding.DateTimeUnit.HOUR_OF_DAY);
DateDimension d1 = new DateDimension("name", d1CalendarIntervals);
DateDimension d2 = new DateDimension("name", d1CalendarIntervals);
assertEquals(d1, d2);
d2 = new DateDimension("name1", d1CalendarIntervals);
assertNotEquals(d1, d2);
List<Rounding.DateTimeUnit> d2CalendarIntervals = new ArrayList<>();
d2CalendarIntervals.add(Rounding.DateTimeUnit.HOUR_OF_DAY);
d2CalendarIntervals.add(Rounding.DateTimeUnit.HOUR_OF_DAY);
d2 = new DateDimension("name", d2CalendarIntervals);
assertNotEquals(d1, d2);
NumericDimension n1 = new NumericDimension("name");
NumericDimension n2 = new NumericDimension("name");
assertEquals(n1, n2);
n2 = new NumericDimension("name1");
assertNotEquals(n1, n2);
}

public void testStarTreeField() {
List<MetricStat> m1 = new ArrayList<>();
m1.add(MetricStat.MAX);
Metric metric1 = new Metric("name", m1);
List<Rounding.DateTimeUnit> d1CalendarIntervals = new ArrayList<>();
d1CalendarIntervals.add(Rounding.DateTimeUnit.HOUR_OF_DAY);
DateDimension d1 = new DateDimension("name", d1CalendarIntervals);
NumericDimension n1 = new NumericDimension("numeric");
NumericDimension n2 = new NumericDimension("name1");

List<Metric> metrics = List.of(metric1);
List<Dimension> dims = List.of(d1, n2);
StarTreeFieldConfiguration config = new StarTreeFieldConfiguration(
100,
Set.of("name"),
StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP
);

StarTreeField field1 = new StarTreeField("starTree", dims, metrics, config);
StarTreeField field2 = new StarTreeField("starTree", dims, metrics, config);
assertEquals(field1, field2);

dims = List.of(d1, n2, n1);
field2 = new StarTreeField("starTree", dims, metrics, config);
assertNotEquals(field1, field2);

dims = List.of(d1, n2);
metrics = List.of(metric1, metric1);
field2 = new StarTreeField("starTree", dims, metrics, config);
assertNotEquals(field1, field2);

dims = List.of(d1, n2);
metrics = List.of(metric1);
StarTreeFieldConfiguration config1 = new StarTreeFieldConfiguration(
1000,
Set.of("name"),
StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP
);
field2 = new StarTreeField("starTree", dims, metrics, config1);
assertNotEquals(field1, field2);

config1 = new StarTreeFieldConfiguration(100, Set.of("name", "field2"), StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP);
field2 = new StarTreeField("starTree", dims, metrics, config1);
assertNotEquals(field1, field2);

config1 = new StarTreeFieldConfiguration(100, Set.of("name"), StarTreeFieldConfiguration.StarTreeBuildMode.ON_HEAP);
field2 = new StarTreeField("starTree", dims, metrics, config1);
assertNotEquals(field1, field2);

field2 = new StarTreeField("starTree", dims, metrics, config);
assertEquals(field1, field2);
}

private XContentBuilder getExpandedMapping(String dim, String metric) throws IOException {
return topMapping(b -> {
b.startObject("composite");
Expand Down

0 comments on commit b813450

Please sign in to comment.