-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] New Platform server shim: update file data visualizer routes to …
…use new platform router (#56972) * [ML] change import endpoint call to fileupload plugin, update file analyzer endpoint * [ML] add apiDoc annotation * [ML] AnalysisResult interface, remove url from apidoc.json * [ML] delete import_data.js * [ML] remove caching code, address PR comments * [ML] file import * [ML] apidoc * [ML] schema validation Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
02f309c
commit 4776cd9
Showing
7 changed files
with
319 additions
and
185 deletions.
There are no files selected for viewing
100 changes: 0 additions & 100 deletions
100
x-pack/legacy/plugins/ml/server/models/file_data_visualizer/file_data_visualizer.js
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
x-pack/legacy/plugins/ml/server/models/file_data_visualizer/file_data_visualizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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 Boom from 'boom'; | ||
import { RequestHandlerContext } from 'kibana/server'; | ||
|
||
export type InputData = any[]; | ||
|
||
export interface InputOverrides { | ||
[key: string]: string; | ||
} | ||
|
||
export type FormattedOverrides = InputOverrides & { | ||
column_names: string[]; | ||
has_header_row: boolean; | ||
should_trim_fields: boolean; | ||
}; | ||
|
||
export interface AnalysisResult { | ||
results: { | ||
charset: string; | ||
has_header_row: boolean; | ||
has_byte_order_marker: boolean; | ||
format: string; | ||
field_stats: { | ||
[fieldName: string]: { | ||
count: number; | ||
cardinality: number; | ||
top_hits: Array<{ count: number; value: any }>; | ||
}; | ||
}; | ||
sample_start: string; | ||
num_messages_analyzed: number; | ||
mappings: { | ||
[fieldName: string]: { | ||
type: string; | ||
}; | ||
}; | ||
quote: string; | ||
delimiter: string; | ||
need_client_timezone: boolean; | ||
num_lines_analyzed: number; | ||
column_names: string[]; | ||
}; | ||
overrides?: FormattedOverrides; | ||
} | ||
|
||
export function fileDataVisualizerProvider(context: RequestHandlerContext) { | ||
async function analyzeFile(data: any, overrides: any): Promise<AnalysisResult> { | ||
let results = []; | ||
|
||
try { | ||
results = await context.ml!.mlClient.callAsCurrentUser('ml.fileStructure', { | ||
body: data, | ||
...overrides, | ||
}); | ||
} catch (error) { | ||
const err = error.message !== undefined ? error.message : error; | ||
throw Boom.badRequest(err); | ||
} | ||
|
||
const { hasOverrides, reducedOverrides } = formatOverrides(overrides); | ||
|
||
return { | ||
...(hasOverrides && { overrides: reducedOverrides }), | ||
results, | ||
}; | ||
} | ||
|
||
return { | ||
analyzeFile, | ||
}; | ||
} | ||
|
||
function formatOverrides(overrides: InputOverrides) { | ||
let hasOverrides = false; | ||
|
||
const reducedOverrides: FormattedOverrides = Object.keys(overrides).reduce((acc, overrideKey) => { | ||
const overrideValue: string = overrides[overrideKey]; | ||
if (overrideValue !== '') { | ||
if (overrideKey === 'column_names') { | ||
acc.column_names = overrideValue.split(','); | ||
} else if (overrideKey === 'has_header_row') { | ||
acc.has_header_row = overrideValue === 'true'; | ||
} else if (overrideKey === 'should_trim_fields') { | ||
acc.should_trim_fields = overrideValue === 'true'; | ||
} else { | ||
acc[overrideKey] = overrideValue; | ||
} | ||
|
||
hasOverrides = true; | ||
} | ||
return acc; | ||
}, {} as FormattedOverrides); | ||
|
||
return { | ||
reducedOverrides, | ||
hasOverrides, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.