Skip to content

Commit

Permalink
Make each analysis report desired field mappings to be copied (elasti…
Browse files Browse the repository at this point in the history
  • Loading branch information
przemekwitek authored and SivagurunathanV committed Jan 21, 2020
1 parent a16d7c0 commit 9d7fbe0
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ public Map<String, Long> getFieldCardinalityLimits() {
return Collections.singletonMap(dependentVariable, 2L);
}

@Override
public Map<String, String> getExplicitlyMappedFields(String resultsFieldName) {
return new HashMap<>() {{
put(resultsFieldName + "." + predictionFieldName, dependentVariable);
put(resultsFieldName + ".top_classes.class_name", dependentVariable);
}};
}

@Override
public boolean supportsMissingValues() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public interface DataFrameAnalysis extends ToXContentObject, NamedWriteable {
*/
Map<String, Long> getFieldCardinalityLimits();

/**
* Returns fields for which the mappings should be copied from source index to destination index.
* Each entry of the returned {@link Map} is of the form:
* key - field path in the destination index
* value - field path in the source index from which the mapping should be taken
*
* @param resultsFieldName name of the results field under which all the results are stored
* @return {@link Map} containing fields for which the mappings should be copied from source index to destination index
*/
Map<String, String> getExplicitlyMappedFields(String resultsFieldName);

/**
* @return {@code true} if this analysis supports data frame rows with missing values
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public Map<String, Long> getFieldCardinalityLimits() {
return Collections.emptyMap();
}

@Override
public Map<String, String> getExplicitlyMappedFields(String resultsFieldName) {
return Collections.emptyMap();
}

@Override
public boolean supportsMissingValues() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public Map<String, Long> getFieldCardinalityLimits() {
return Collections.emptyMap();
}

@Override
public Map<String, String> getExplicitlyMappedFields(String resultsFieldName) {
return Collections.singletonMap(resultsFieldName + "." + predictionFieldName, dependentVariable);
}

@Override
public boolean supportsMissingValues() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.util.Map;
import java.util.Set;

import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -162,8 +164,16 @@ public void testGetParams() {
"prediction_field_type", "string")));
}

public void testFieldCardinalityLimitsIsNonNull() {
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(nullValue())));
public void testRequiredFieldsIsNonEmpty() {
assertThat(createTestInstance().getRequiredFields(), is(not(empty())));
}

public void testFieldCardinalityLimitsIsNonEmpty() {
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(anEmptyMap())));
}

public void testFieldMappingsToCopyIsNonEmpty() {
assertThat(createTestInstance().getExplicitlyMappedFields(""), is(not(anEmptyMap())));
}

public void testToXContent_GivenVersionBeforeRandomizeSeedWasIntroduced() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import java.io.IOException;
import java.util.Map;

import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

public class OutlierDetectionTests extends AbstractSerializingTestCase<OutlierDetection> {

Expand Down Expand Up @@ -84,8 +84,16 @@ public void testGetParams_GivenExplicitValues() {
assertThat(params.get(OutlierDetection.STANDARDIZATION_ENABLED.getPreferredName()), is(false));
}

public void testFieldCardinalityLimitsIsNonNull() {
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(nullValue())));
public void testRequiredFieldsIsEmpty() {
assertThat(createTestInstance().getRequiredFields(), is(empty()));
}

public void testFieldCardinalityLimitsIsEmpty() {
assertThat(createTestInstance().getFieldCardinalityLimits(), is(anEmptyMap()));
}

public void testFieldMappingsToCopyIsEmpty() {
assertThat(createTestInstance().getExplicitlyMappedFields(""), is(anEmptyMap()));
}

public void testGetStateDocId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.util.Collections;
import java.util.Map;

import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -99,8 +101,16 @@ public void testGetParams() {
equalTo(Map.of("dependent_variable", "foo", "prediction_field_name", "foo_prediction")));
}

public void testFieldCardinalityLimitsIsNonNull() {
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(nullValue())));
public void testRequiredFieldsIsNonEmpty() {
assertThat(createTestInstance().getRequiredFields(), is(not(empty())));
}

public void testFieldCardinalityLimitsIsEmpty() {
assertThat(createTestInstance().getFieldCardinalityLimits(), is(anEmptyMap()));
}

public void testFieldMappingsToCopyIsNonEmpty() {
assertThat(createTestInstance().getExplicitlyMappedFields(""), is(not(anEmptyMap())));
}

public void testGetStateDocId() {
Expand Down
Loading

0 comments on commit 9d7fbe0

Please sign in to comment.