Skip to content

Commit

Permalink
[ML] DF Analytics creation: ensure advanced editor can be validated w…
Browse files Browse the repository at this point in the history
…hen empty (#52831)

* Check for undefined analysis config before validating

* update tests
  • Loading branch information
alvarezmelissa87 authored Dec 12, 2019
1 parent 0cd5bb0 commit deee1c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SourceIndex = DataFrameAnalyticsConfig['source']['index'];

const getMockState = ({
index,
modelMemoryLimit,
modelMemoryLimit = '100mb',
}: {
index: SourceIndex;
modelMemoryLimit?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const getSourceIndexString = (state: State) => {
};

export const validateAdvancedEditor = (state: State): State => {
const { jobIdEmpty, jobIdValid, jobIdExists, createIndexPattern } = state.form;
const { jobIdEmpty, jobIdValid, jobIdExists, jobType, createIndexPattern } = state.form;
const { jobConfig } = state;

state.advancedEditorMessages = [];
Expand Down Expand Up @@ -85,14 +85,25 @@ export const validateAdvancedEditor = (state: State): State => {
const destinationIndexPatternTitleExists =
state.indexPatternsMap[destinationIndexName] !== undefined;
const mml = jobConfig.model_memory_limit;
const modelMemoryLimitEmpty = mml === '';
const modelMemoryLimitEmpty = mml === '' || mml === undefined;
if (!modelMemoryLimitEmpty && mml !== undefined) {
const { valid } = validateModelMemoryLimitUnits(mml);
state.form.modelMemoryLimitUnitValid = valid;
}

let dependentVariableEmpty = false;
if (isRegressionAnalysis(jobConfig.analysis) || isClassificationAnalysis(jobConfig.analysis)) {

if (
jobConfig.analysis === undefined &&
(jobType === JOB_TYPES.CLASSIFICATION || jobType === JOB_TYPES.REGRESSION)
) {
dependentVariableEmpty = true;
}

if (
jobConfig.analysis !== undefined &&
(isRegressionAnalysis(jobConfig.analysis) || isClassificationAnalysis(jobConfig.analysis))
) {
const dependentVariableName = getDependentVar(jobConfig.analysis) || '';
dependentVariableEmpty = dependentVariableName === '';
}
Expand Down

0 comments on commit deee1c0

Please sign in to comment.