mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[ML] Data Frame Analytics creation: ensure included fields selection table is shown when no docs contain all mapped fields (#104191)
* use indexPatternFields if explain error due to missing values in docs * fix types
This commit is contained in:
parent
d5ca242098
commit
ebc103f619
5 changed files with 47 additions and 6 deletions
|
@ -82,6 +82,7 @@ export interface UseIndexDataReturnType
|
|||
| 'resultsField'
|
||||
> {
|
||||
renderCellValue: RenderCellValue;
|
||||
indexPatternFields?: string[];
|
||||
}
|
||||
|
||||
export interface UseDataGridReturnType {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
>();
|
||||
|
@ -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) {
|
||||
|
@ -286,6 +291,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
|
|||
setFieldOptionsFetchFail(false);
|
||||
setMaxDistinctValuesError(undefined);
|
||||
setUnsupportedFieldsError(undefined);
|
||||
setNoDocsContainMappedFields(false);
|
||||
setIncludesTableItems(fieldSelection ? fieldSelection : []);
|
||||
}
|
||||
|
||||
|
@ -315,6 +321,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
|
|||
setFieldOptionsFetchFail(true);
|
||||
setMaxDistinctValuesError(maxDistinctValuesErrorMessage);
|
||||
setUnsupportedFieldsError(unsupportedFieldsErrorMessage);
|
||||
setNoDocsContainMappedFields(noDocsWithFields);
|
||||
setFetchingExplainData(false);
|
||||
setFormState({
|
||||
...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: fallbackModelMemoryLimit } : {}),
|
||||
|
@ -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 });
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
|
@ -444,6 +468,7 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
|
|||
|
||||
setMaxDistinctValuesError(maxDistinctValuesErrorMessage);
|
||||
setUnsupportedFieldsError(unsupportedFieldsErrorMessage);
|
||||
setNoDocsContainMappedFields(noDocsWithFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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} />
|
||||
|
@ -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}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -255,6 +255,7 @@ export const useIndexData = (
|
|||
|
||||
return {
|
||||
...dataGrid,
|
||||
indexPatternFields,
|
||||
renderCellValue,
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue