@@ -48,6 +48,9 @@ import { getNestedProperty } from '../../util/object_utils';
4848import { mlFieldFormatService } from '../../services/field_format_service' ;
4949
5050import { DataGridItem , IndexPagination , RenderCellValue } from './types' ;
51+ import type { RuntimeField } from '../../../../../../../src/plugins/data/common/index_patterns' ;
52+ import { RuntimeMappings } from '../../../../common/types/fields' ;
53+ import { isPopulatedObject } from '../../../../common/util/object_utils' ;
5154
5255export const INIT_MAX_COLUMNS = 10 ;
5356
@@ -86,6 +89,37 @@ export const getFieldsFromKibanaIndexPattern = (indexPattern: IndexPattern): str
8689 return indexPatternFields ;
8790} ;
8891
92+ /**
93+ * Return a map of runtime_mappings for each of the index pattern field provided
94+ * to provide in ES search queries
95+ * @param indexPatternFields
96+ * @param indexPattern
97+ * @param clonedRuntimeMappings
98+ */
99+ export const getRuntimeFieldsMapping = (
100+ indexPatternFields : string [ ] | undefined ,
101+ indexPattern : IndexPattern | undefined ,
102+ clonedRuntimeMappings ?: RuntimeMappings
103+ ) => {
104+ if ( ! Array . isArray ( indexPatternFields ) || indexPattern === undefined ) return { } ;
105+ const ipRuntimeMappings = indexPattern . getComputedFields ( ) . runtimeFields ;
106+ let combinedRuntimeMappings : RuntimeMappings = { } ;
107+
108+ if ( isPopulatedObject ( ipRuntimeMappings ) ) {
109+ indexPatternFields . forEach ( ( ipField ) => {
110+ if ( ipRuntimeMappings . hasOwnProperty ( ipField ) ) {
111+ combinedRuntimeMappings [ ipField ] = ipRuntimeMappings [ ipField ] ;
112+ }
113+ } ) ;
114+ }
115+ if ( isPopulatedObject ( clonedRuntimeMappings ) ) {
116+ combinedRuntimeMappings = { ...combinedRuntimeMappings , ...clonedRuntimeMappings } ;
117+ }
118+ return Object . keys ( combinedRuntimeMappings ) . length > 0
119+ ? { runtime_mappings : combinedRuntimeMappings }
120+ : { } ;
121+ } ;
122+
89123export interface FieldTypes {
90124 [ key : string ] : ES_FIELD_TYPES ;
91125}
@@ -135,6 +169,45 @@ export const getDataGridSchemasFromFieldTypes = (fieldTypes: FieldTypes, results
135169} ;
136170
137171export const NON_AGGREGATABLE = 'non-aggregatable' ;
172+
173+ export const getDataGridSchemaFromESFieldType = (
174+ fieldType : ES_FIELD_TYPES | undefined | RuntimeField [ 'type' ]
175+ ) : string | undefined => {
176+ // Built-in values are ['boolean', 'currency', 'datetime', 'numeric', 'json']
177+ // To fall back to the default string schema it needs to be undefined.
178+ let schema ;
179+
180+ switch ( fieldType ) {
181+ case ES_FIELD_TYPES . GEO_POINT :
182+ case ES_FIELD_TYPES . GEO_SHAPE :
183+ schema = 'json' ;
184+ break ;
185+ case ES_FIELD_TYPES . BOOLEAN :
186+ schema = 'boolean' ;
187+ break ;
188+ case ES_FIELD_TYPES . DATE :
189+ case ES_FIELD_TYPES . DATE_NANOS :
190+ schema = 'datetime' ;
191+ break ;
192+ case ES_FIELD_TYPES . BYTE :
193+ case ES_FIELD_TYPES . DOUBLE :
194+ case ES_FIELD_TYPES . FLOAT :
195+ case ES_FIELD_TYPES . HALF_FLOAT :
196+ case ES_FIELD_TYPES . INTEGER :
197+ case ES_FIELD_TYPES . LONG :
198+ case ES_FIELD_TYPES . SCALED_FLOAT :
199+ case ES_FIELD_TYPES . SHORT :
200+ schema = 'numeric' ;
201+ break ;
202+ // keep schema undefined for text based columns
203+ case ES_FIELD_TYPES . KEYWORD :
204+ case ES_FIELD_TYPES . TEXT :
205+ break ;
206+ }
207+
208+ return schema ;
209+ } ;
210+
138211export const getDataGridSchemaFromKibanaFieldType = (
139212 field : IFieldType | undefined
140213) : string | undefined => {
0 commit comments