Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Transforms: Fix pivot preview table mapping. #60609

Merged
merged 4 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/transform/public/app/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export {
TRANSFORM_MODE,
} from './transform_stats';
export { getDiscoverUrl } from './navigation';
export { GetTransformsResponse, PreviewData, PreviewMappings } from './pivot_preview';
export {
getEsAggFromAggConfig,
isPivotAggsConfigWithUiSupport,
Expand Down
29 changes: 29 additions & 0 deletions x-pack/plugins/transform/public/app/common/pivot_preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ES_FIELD_TYPES } from '../../../../../../src/plugins/data/public';

import { Dictionary } from '../../../common/types/common';

interface EsMappingType {
type: ES_FIELD_TYPES;
}

export type PreviewItem = Dictionary<any>;
export type PreviewData = PreviewItem[];
export interface PreviewMappings {
properties: Dictionary<EsMappingType>;
}

export interface GetTransformsResponse {
preview: PreviewData;
generated_dest_index: {
mappings: PreviewMappings;
// Not in use yet
aliases: any;
settings: any;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import { useEffect, useState } from 'react';
import { dictionaryToArray } from '../../../../common/types/common';
import { useApi } from '../../hooks/use_api';

import { Dictionary } from '../../../../common/types/common';
import { IndexPattern, ES_FIELD_TYPES } from '../../../../../../../src/plugins/data/public';
import { IndexPattern } from '../../../../../../../src/plugins/data/public';

import {
getPreviewRequestBody,
PreviewRequestBody,
PivotAggsConfigDict,
PivotGroupByConfigDict,
PivotQuery,
PreviewData,
PreviewMappings,
} from '../../common';

export enum PIVOT_PREVIEW_STATUS {
Expand All @@ -27,16 +28,6 @@ export enum PIVOT_PREVIEW_STATUS {
ERROR,
}

interface EsMappingType {
type: ES_FIELD_TYPES;
}

export type PreviewItem = Dictionary<any>;
type PreviewData = PreviewItem[];
interface PreviewMappings {
properties: Dictionary<EsMappingType>;
}

export interface UsePivotPreviewDataReturnType {
errorMessage: string;
status: PIVOT_PREVIEW_STATUS;
Expand All @@ -45,11 +36,6 @@ export interface UsePivotPreviewDataReturnType {
previewRequest: PreviewRequestBody;
}

export interface GetTransformsResponse {
preview: PreviewData;
mappings: PreviewMappings;
}

export const usePivotPreviewData = (
indexPatternTitle: IndexPattern['title'],
query: PivotQuery,
Expand Down Expand Up @@ -77,9 +63,9 @@ export const usePivotPreviewData = (
setStatus(PIVOT_PREVIEW_STATUS.LOADING);

try {
const resp: GetTransformsResponse = await api.getTransformsPreview(previewRequest);
const resp = await api.getTransformsPreview(previewRequest);
setPreviewData(resp.preview);
setPreviewMappings(resp.mappings);
setPreviewMappings(resp.generated_dest_index.mappings);
setStatus(PIVOT_PREVIEW_STATUS.LOADED);
} catch (e) {
setErrorMessage(JSON.stringify(e, null, 2));
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/transform/public/app/hooks/use_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TransformId, TransformEndpointRequest, TransformEndpointResult } from '
import { API_BASE_PATH } from '../../../common/constants';

import { useAppDependencies } from '../app_dependencies';
import { PreviewRequestBody } from '../common';
import { GetTransformsResponse, PreviewRequestBody } from '../common';

import { EsIndex } from './use_api_types';

Expand Down Expand Up @@ -37,7 +37,7 @@ export const useApi = () => {
body: JSON.stringify(transformsInfo),
});
},
getTransformsPreview(obj: PreviewRequestBody): Promise<any> {
getTransformsPreview(obj: PreviewRequestBody): Promise<GetTransformsResponse> {
return http.post(`${API_BASE_PATH}transforms/_preview`, { body: JSON.stringify(obj) });
},
startTransforms(transformsInfo: TransformEndpointRequest[]): Promise<TransformEndpointResult> {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/test/functional/apps/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function({ getService, loadTestFile }: FtrProviderContext) {
const transform = getService('transform');

// prevent test failures with current ES snapshot, see https://github.com/elastic/kibana/issues/60516
describe.skip('transform', function() {
describe('transform', function() {
this.tags(['ciGroup9', 'transform']);

before(async () => {
Expand Down