@@ -226,6 +226,33 @@ const procPipelineStep = (pipelineStep, data, sourceFields) => {
226
226
data = groupBy ( data , ( item ) =>
227
227
keysToGroupBy . map ( ( key ) => get ( item , key ) )
228
228
) ;
229
+ // Mapping between new group keys and data path
230
+ const mapping : Record < string , string > = { } ;
231
+ for ( const key of keysToGroupBy ) {
232
+ // Check if the key contains a '.'
233
+ if ( key . includes ( '.' ) ) {
234
+ // Split the key by '.' and extract the last part
235
+ const newKey = key . split ( '.' ) . pop ( ) ;
236
+ mapping [ newKey ] = key ;
237
+ } else {
238
+ mapping [ key ] = key ;
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Transform object, using mapping object
244
+ *
245
+ * @param obj Object to transform
246
+ * @returns Transformed object
247
+ */
248
+ const transformObject = ( obj : Record < string , any > ) => {
249
+ const newObj : Record < string , any > = { } ;
250
+ for ( const [ key , path ] of Object . entries ( mapping ) ) {
251
+ newObj [ key ] = get ( obj , path ) ;
252
+ }
253
+ return newObj ;
254
+ } ;
255
+
229
256
for ( const key in data ) {
230
257
let supplementaryFields : any ;
231
258
for ( const operator of operators ) {
@@ -245,7 +272,7 @@ const procPipelineStep = (pipelineStep, data, sourceFields) => {
245
272
data [ key ] ,
246
273
operators . map ( ( operator ) => operator . operator )
247
274
) ,
248
- ...pick ( data [ key ] . initialData [ 0 ] , keysToGroupBy ) ,
275
+ ...transformObject ( data [ key ] . initialData [ 0 ] ) ,
249
276
} ) ;
250
277
}
251
278
return dataToKeep ;
0 commit comments