Skip to content

Commit

Permalink
[ML] Data Frame Analytics creation: ensure included fields selection …
Browse files Browse the repository at this point in the history
…table is shown when no docs contain all mapped fields (#104191)

* use indexPatternFields if explain error due to missing values in docs

* fix types
  • Loading branch information
alvarezmelissa87 authored Jul 6, 2021
1 parent d5ca242 commit ebc103f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface UseIndexDataReturnType
| 'resultsField'
> {
renderCellValue: RenderCellValue;
indexPatternFields?: string[];
}

export interface UseDataGridReturnType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export enum INDEX_STATUS {

export interface FieldSelectionItem {
name: string;
mappings_types: string[];
mappings_types?: string[];
is_included: boolean;
is_required: boolean;
feature_type?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
const [fetchingExplainData, setFetchingExplainData] = useState<boolean>(false);
const [maxDistinctValuesError, setMaxDistinctValuesError] = useState<string | undefined>();
const [unsupportedFieldsError, setUnsupportedFieldsError] = useState<string | undefined>();
const [noDocsContainMappedFields, setNoDocsContainMappedFields] = useState<boolean>(false);
const [minimumFieldsRequiredMessage, setMinimumFieldsRequiredMessage] = useState<
undefined | string
>();
Expand Down Expand Up @@ -261,9 +262,13 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
formToUse.includes = [...includes, dependentVariable];
}

const { success, expectedMemory, fieldSelection, errorMessage } = await fetchExplainData(
formToUse
);
const {
success,
expectedMemory,
fieldSelection,
errorMessage,
noDocsContainMappedFields: noDocsWithFields,
} = await fetchExplainData(formToUse);

if (success) {
if (shouldUpdateEstimatedMml) {
Expand All @@ -286,6 +291,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
setFieldOptionsFetchFail(false);
setMaxDistinctValuesError(undefined);
setUnsupportedFieldsError(undefined);
setNoDocsContainMappedFields(false);
setIncludesTableItems(fieldSelection ? fieldSelection : []);
}

Expand Down Expand Up @@ -315,6 +321,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
setFieldOptionsFetchFail(true);
setMaxDistinctValuesError(maxDistinctValuesErrorMessage);
setUnsupportedFieldsError(unsupportedFieldsErrorMessage);
setNoDocsContainMappedFields(noDocsWithFields);
setFetchingExplainData(false);
setFormState({
...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: fallbackModelMemoryLimit } : {}),
Expand All @@ -326,6 +333,17 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
setFormState({ sourceIndex: currentIndexPattern.title });
}, []);

const indexPatternFieldsTableItems = useMemo(() => {
if (indexData?.indexPatternFields !== undefined) {
return indexData.indexPatternFields.map((field) => ({
name: field,
is_included: false,
is_required: false,
}));
}
return [];
}, [`${indexData?.indexPatternFields}`]);

useEffect(() => {
if (typeof savedSearchQueryStr === 'string') {
setFormState({ jobConfigQuery: savedSearchQuery, jobConfigQueryString: savedSearchQueryStr });
Expand Down Expand Up @@ -399,7 +417,12 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
? [...updatedIncludes, dependentVariable]
: updatedIncludes;

const { success, fieldSelection, errorMessage } = await fetchExplainData(formCopy);
const {
success,
fieldSelection,
errorMessage,
noDocsContainMappedFields: noDocsWithFields,
} = await fetchExplainData(formCopy);
if (success) {
// update the field selection table
const hasRequiredFields = fieldSelection.some(
Expand All @@ -423,6 +446,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
setIncludesTableItems(updatedFieldSelection ? updatedFieldSelection : fieldSelection);
setMaxDistinctValuesError(undefined);
setUnsupportedFieldsError(undefined);
setNoDocsContainMappedFields(noDocsWithFields);
setFormState({
includes: updatedIncludes,
requiredFieldsError: !hasRequiredFields ? requiredFieldsErrorText : undefined,
Expand All @@ -444,6 +468,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({

setMaxDistinctValuesError(maxDistinctValuesErrorMessage);
setUnsupportedFieldsError(unsupportedFieldsErrorMessage);
setNoDocsContainMappedFields(noDocsWithFields);
}
}
}
Expand Down Expand Up @@ -501,6 +526,11 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
// `undefined` means uninitialized, `null` means initialized but not used.
if (savedSearchQuery === undefined) return null;

const tableItems =
includesTableItems.length > 0 && !noDocsContainMappedFields
? includesTableItems
: indexPatternFieldsTableItems;

return (
<Fragment>
<Messages messages={requestMessages} />
Expand Down Expand Up @@ -649,7 +679,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
includes={includes}
minimumFieldsRequiredMessage={minimumFieldsRequiredMessage}
setMinimumFieldsRequiredMessage={setMinimumFieldsRequiredMessage}
tableItems={includesTableItems}
tableItems={firstUpdate.current ? includesTableItems : tableItems}
unsupportedFieldsError={unsupportedFieldsError}
setUnsupportedFieldsError={setUnsupportedFieldsError}
setFormState={setFormState}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const fetchExplainData = async (formState: State['form']) => {
let success = true;
let expectedMemory = '';
let fieldSelection: FieldSelectionItem[] = [];
let noDocsContainMappedFields = false;

try {
delete jobConfig.dest;
Expand All @@ -45,11 +46,19 @@ export const fetchExplainData = async (formState: State['form']) => {
}
}

if (
errorMessage.includes('status_exception') &&
errorMessage.includes('Unable to estimate memory usage as no documents')
) {
noDocsContainMappedFields = true;
}

return {
success,
expectedMemory,
fieldSelection,
errorMessage,
errorReason,
noDocsContainMappedFields,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const useIndexData = (

return {
...dataGrid,
indexPatternFields,
renderCellValue,
};
};

0 comments on commit ebc103f

Please sign in to comment.