diff --git a/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.test.ts b/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.test.ts index e7c66a676c9..d96cd98122f 100644 --- a/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.test.ts +++ b/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.test.ts @@ -78,6 +78,8 @@ describe('timeSeriesTableTransformer', () => { const series = [ getTimeSeries('A', { instance: 'A', pod: 'B' }, [4, 2, 3]), getTimeSeries('B', { instance: 'A', pod: 'C' }, [3, 4, 5]), + getTimeSeries('C', { instance: 'B', pod: 'X' }, [4, 2, 0]), + getTimeSeries('D', { instance: 'B', pod: 'Y' }, [0, 0, 0]), ]; const results = timeSeriesToTableTransform( @@ -85,12 +87,35 @@ describe('timeSeriesTableTransformer', () => { B: { stat: ReducerID.mean, }, + D: { + stat: ReducerID.mean, + }, }, series ); expect(results[0].fields[2].values[0].value).toEqual(3); expect(results[1].fields[2].values[0].value).toEqual(4); + expect(results[2].fields[2].values[0].value).toEqual(0); + expect(results[3].fields[2].values[0].value).toEqual(0); + }); + + it('calculate the value for an empty series to null', () => { + const series = [getTimeSeries('D', { instance: 'B', pod: 'Y' }, [])]; + + const results = timeSeriesToTableTransform( + { + B: { + stat: ReducerID.mean, + }, + D: { + stat: ReducerID.mean, + }, + }, + series + ); + + expect(results[0].fields[2].values[0].value).toEqual(null); }); }); diff --git a/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.ts b/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.ts index dfe99397e30..8205accb0c2 100644 --- a/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.ts +++ b/public/app/features/transformers/timeSeriesTable/timeSeriesTableTransformer.ts @@ -172,7 +172,7 @@ export function timeSeriesToTableTransform(options: TimeSeriesTableTransformerOp // and push the frame with reduction // into the the appropriate field const reducerId = options[refId]?.stat ?? ReducerID.lastNotNull; - const value = reduceField({ field, reducers: [reducerId] })[reducerId] || null; + const value = reduceField({ field, reducers: [reducerId] })[reducerId] ?? null; // Push the appropriate time and value frame // to the trend frame for the sparkline