Skip to content

Commit fafa169

Browse files
committed
clean up
Signed-off-by: Jackie Han <jkhanjob@gmail.com>
1 parent 41d5949 commit fafa169

File tree

8 files changed

+300
-226
lines changed

8 files changed

+300
-226
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ systemProp.org.gradle.warning.mode=fail
2727
systemProp.jdk.tls.client.protocols=TLSv1.2
2828

2929
# jvm args for faster test execution by default
30-
systemProp.tests.jvm.argline=-XX:TieredStopAtLevel=1 -XX:ReservedCodeCacheSize=64m
30+
systemProp.tests.jvm.argline=-XX:TieredStopAtLevel=1 -XX:ReservedCodeCacheSize=64m

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
7-
zipStorePath=wrapper/dists
7+
zipStorePath=wrapper/dists

src/main/java/org/opensearch/ad/indices/ADIndexManagement.java

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.opensearch.ad.settings.AnomalyDetectorSettings.ANOMALY_DETECTION_STATE_INDEX_MAPPING_FILE;
2020
import static org.opensearch.ad.settings.AnomalyDetectorSettings.ANOMALY_RESULTS_INDEX_MAPPING_FILE;
2121
import static org.opensearch.ad.settings.AnomalyDetectorSettings.CHECKPOINT_INDEX_MAPPING_FILE;
22-
import static org.opensearch.ad.settings.AnomalyDetectorSettings.FLATTENED_ANOMALY_RESULTS_INDEX_MAPPING_FILE;
2322

2423
import java.io.IOException;
2524
import java.util.EnumMap;

src/main/java/org/opensearch/timeseries/indices/IndexManagement.java

+6
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ protected static String getMappings(String mappingFileRelativePath) throws IOExc
273273
return Resources.toString(url, Charsets.UTF_8);
274274
}
275275

276+
public static String getScripts(String scriptFileRelativePath) throws IOException {
277+
URL url = IndexManagement.class.getClassLoader().getResource(scriptFileRelativePath);
278+
return Resources.toString(url, Charsets.UTF_8);
279+
}
280+
281+
276282
protected void choosePrimaryShards(CreateIndexRequest request, boolean hiddenIndex) {
277283
request
278284
.settings(

src/main/java/org/opensearch/timeseries/rest/handler/AbstractTimeSeriesActionHandler.java

+223-222
Large diffs are not rendered by default.

src/main/java/org/opensearch/timeseries/settings/TimeSeriesSettings.java

+2
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,6 @@ public class TimeSeriesSettings {
289289

290290
// max entities to track per detector
291291
public static final int MAX_TRACKING_ENTITIES = 1000000;
292+
293+
public static final String FLATTEN_CUSTOM_RESULT_INDEX_PAINLESS = "scripts/flatten-custom-result-index-painless.txt";
292294
}

src/main/java/org/opensearch/timeseries/transport/ResultBulkTransportAction.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.opensearch.action.support.ActionFilters;
2727
import org.opensearch.action.support.HandledTransportAction;
2828
import org.opensearch.client.Client;
29-
import org.opensearch.cluster.service.ClusterService;
3029
import org.opensearch.common.settings.Settings;
3130
import org.opensearch.core.action.ActionListener;
3231
import org.opensearch.core.common.io.stream.Writeable;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Create a map to store the relationship between feature_id and feature_name from feature_data
2+
def featureNameMap = [:];
3+
4+
// Populate the map from feature_data
5+
if (ctx.containsKey('feature_data') && ctx.feature_data != null) {
6+
for (int i = 0; i < ctx.feature_data.length; i++) {
7+
def feature = ctx.feature_data[i];
8+
if (feature != null && feature.containsKey('feature_id') && feature.containsKey('feature_name')) {
9+
featureNameMap[feature.feature_id] = feature.feature_name;
10+
ctx['feature_data_' + feature.feature_name] = feature.data; // Flatten feature_data as before
11+
}
12+
}
13+
}
14+
15+
// Flatten nested entity field
16+
if (ctx.containsKey('entity') && ctx.entity != null) {
17+
for (int i = 0; i < ctx.entity.length; i++) {
18+
def entity = ctx.entity[i];
19+
if (entity != null && entity.containsKey('name') && entity.containsKey('value')) {
20+
ctx['entity_' + entity.name] = entity.value;
21+
}
22+
}
23+
}
24+
25+
// Flatten nested relevant_attribution field
26+
if (ctx.containsKey('relevant_attribution') && ctx.relevant_attribution != null) {
27+
for (int i = 0; i < ctx.relevant_attribution.length; i++) {
28+
def attribution = ctx.relevant_attribution[i];
29+
if (attribution != null && attribution.containsKey('feature_id') && attribution.containsKey('data')) {
30+
def featureName = featureNameMap[attribution.feature_id];
31+
if (featureName != null) {
32+
ctx['relevant_attribution_' + featureName] = attribution.data;
33+
}
34+
}
35+
}
36+
}
37+
38+
// Flatten nested expected_values field
39+
if (ctx.containsKey('expected_values') && ctx.expected_values != null) {
40+
for (int i = 0; i < ctx.expected_values.length; i++) {
41+
def expected = ctx.expected_values[i];
42+
if (expected != null && expected.containsKey('value_list') && expected.value_list != null) {
43+
for (int j = 0; j < expected.value_list.length; j++) {
44+
def value = expected.value_list[j];
45+
if (value != null && value.containsKey('feature_id') && value.containsKey('data')) {
46+
def featureName = featureNameMap[value.feature_id];
47+
if (featureName != null) {
48+
ctx['expected_values_' + featureName] = value.data;
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
// Flatten nested past_values field
57+
if (ctx.containsKey('past_values') && ctx.past_values != null) {
58+
for (int i = 0; i < ctx.past_values.length; i++) {
59+
def pastValue = ctx.past_values[i];
60+
if (pastValue != null && pastValue.containsKey('feature_id') && pastValue.containsKey('data')) {
61+
def featureName = featureNameMap[pastValue.feature_id];
62+
if (featureName != null) {
63+
ctx['past_value_' + featureName] = pastValue.data;
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)