Skip to content

Commit

Permalink
[ML] Update to using estypes.RuntimeField
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Mar 26, 2021
1 parent b68e736 commit 54b62f8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/ml/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export { ChartData } from './types/field_histograms';
export { ANOMALY_SEVERITY, ANOMALY_THRESHOLD, SEVERITY_COLORS } from './constants/anomalies';
export { getSeverityColor, getSeverityType } from './util/anomaly_utils';
export { composeValidators, patternValidator } from './util/validators';
export { isRuntimeMappings, isRuntimeField } from './util/runtime_field_utils';
export { extractErrorMessage } from './util/errors';
export type { RuntimeMappings } from './types/fields';
17 changes: 2 additions & 15 deletions x-pack/plugins/ml/common/types/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Field {
aggregatable?: boolean;
aggIds?: AggId[];
aggs?: Aggregation[];
runtimeField?: RuntimeField;
runtimeField?: estypes.RuntimeField;
}

export interface Aggregation {
Expand Down Expand Up @@ -108,17 +108,4 @@ export interface AggCardinality {

export type RollupFields = Record<FieldId, [Record<'agg', ES_AGGREGATION>]>;

// Replace this with import once #88995 is merged
const RUNTIME_FIELD_TYPES = ['keyword', 'long', 'double', 'date', 'ip', 'boolean'] as const;
type RuntimeType = typeof RUNTIME_FIELD_TYPES[number];

export interface RuntimeField {
type: RuntimeType;
script?:
| string
| {
source: string;
};
}

export type RuntimeMappings = estypes.RuntimeFields;
export type RuntimeMappings = Record<string, estypes.RuntimeField>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { isRuntimeField, isRuntimeMappings } from './types';
import { isRuntimeField, isRuntimeMappings } from './runtime_field_utils';

describe('Transform: step_define type guards', () => {
it('isRuntimeField()', () => {
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/ml/common/util/runtime_field_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
* 2.0.
*/

import { estypes } from '@elastic/elasticsearch';
import { isPopulatedObject } from './object_utils';
import {
RUNTIME_FIELD_TYPES,
RuntimeType,
} from '../../../../../src/plugins/data/common/index_patterns';
import type { RuntimeField, RuntimeMappings } from '../types/fields';
import type { RuntimeMappings } from '../types/fields';

export function isRuntimeField(arg: unknown): arg is RuntimeField {
export function isRuntimeField(arg: unknown): arg is estypes.RuntimeField {
return (
isPopulatedObject(arg) &&
((Object.keys(arg).length === 1 && arg.hasOwnProperty('type')) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { i18n } from '@kbn/i18n';

import { CoreSetup } from 'src/core/public';

import type { estypes } from '@elastic/elasticsearch';
import {
IndexPattern,
IFieldType,
Expand Down Expand Up @@ -49,7 +50,6 @@ import { getNestedProperty } from '../../util/object_utils';
import { mlFieldFormatService } from '../../services/field_format_service';

import { DataGridItem, IndexPagination, RenderCellValue } from './types';
import type { RuntimeField } from '../../../../../../../src/plugins/data/common/index_patterns';
import { RuntimeMappings } from '../../../../common/types/fields';
import { isPopulatedObject } from '../../../../common/util/object_utils';

Expand Down Expand Up @@ -178,7 +178,7 @@ export const getDataGridSchemasFromFieldTypes = (fieldTypes: FieldTypes, results
export const NON_AGGREGATABLE = 'non-aggregatable';

export const getDataGridSchemaFromESFieldType = (
fieldType: ES_FIELD_TYPES | undefined | RuntimeField['type']
fieldType: ES_FIELD_TYPES | undefined | estypes.RuntimeField['type']
): string | undefined => {
// Built-in values are ['boolean', 'currency', 'datetime', 'numeric', 'json']
// To fall back to the default string schema it needs to be undefined.
Expand Down

0 comments on commit 54b62f8

Please sign in to comment.