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 committed Dec 20, 2019
1 parent a383778 commit d7f17c9
Show file tree
Hide file tree
Showing 18 changed files with 439 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,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 @@ -25,7 +25,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.hasEntry;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -161,8 +163,16 @@ public void testGetParams() {
hasEntry("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 static org.hamcrest.Matchers.allOf;
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.hasEntry;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -100,8 +102,16 @@ public void testGetParams() {
allOf(hasEntry("dependent_variable", "foo"), hasEntry("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 d7f17c9

Please sign in to comment.