[v9.4.x] Transformations: Selectively apply transformation to queries (#62615)
Transformations: Selectively apply transformation to queries (#61735)
(cherry picked from commit bba80b6c7a)
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Ryan McKinley
parent
90a4c84bc2
commit
41b0393140
@@ -3,10 +3,11 @@ import { FieldType } from '../types';
|
||||
import { mockTransformationsRegistry } from '../utils/tests/mockTransformationsRegistry';
|
||||
|
||||
import { ReducerID } from './fieldReducer';
|
||||
import { FrameMatcherID } from './matchers/ids';
|
||||
import { transformDataFrame } from './transformDataFrame';
|
||||
import { filterFieldsByNameTransformer } from './transformers/filterByName';
|
||||
import { DataTransformerID } from './transformers/ids';
|
||||
import { reduceTransformer } from './transformers/reduce';
|
||||
import { reduceTransformer, ReduceTransformerMode } from './transformers/reduce';
|
||||
|
||||
const seriesAWithSingleField = toDataFrame({
|
||||
name: 'A',
|
||||
@@ -73,4 +74,44 @@ describe('transformDataFrame', () => {
|
||||
expect(processed[0].fields[0].values.get(0)).toEqual('temperature');
|
||||
});
|
||||
});
|
||||
|
||||
it('Support filtering', async () => {
|
||||
const frameA = toDataFrame({
|
||||
refId: 'A',
|
||||
fields: [{ name: 'value', type: FieldType.number, values: [5, 6] }],
|
||||
});
|
||||
const frameB = toDataFrame({
|
||||
refId: 'B',
|
||||
fields: [{ name: 'value', type: FieldType.number, values: [7, 8] }],
|
||||
});
|
||||
|
||||
const cfg = [
|
||||
{
|
||||
id: DataTransformerID.reduce,
|
||||
filter: {
|
||||
id: FrameMatcherID.byRefId,
|
||||
options: 'A', // Only apply to A
|
||||
},
|
||||
options: {
|
||||
reducers: [ReducerID.first],
|
||||
mode: ReduceTransformerMode.ReduceFields,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Only apply A
|
||||
await expect(transformDataFrame(cfg, [frameA, frameB])).toEmitValuesWith((received) => {
|
||||
const processed = received[0].map((v) => v.fields[0].values.toArray());
|
||||
expect(processed).toBeTruthy();
|
||||
expect(processed).toMatchObject([[5], [7, 8]]);
|
||||
});
|
||||
|
||||
// Only apply to B
|
||||
cfg[0].filter.options = 'B';
|
||||
await expect(transformDataFrame(cfg, [frameA, frameB])).toEmitValuesWith((received) => {
|
||||
const processed = received[0].map((v) => v.fields[0].values.toArray());
|
||||
expect(processed).toBeTruthy();
|
||||
expect(processed).toMatchObject([[5, 6], [7]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user