clear state.calcs on every append (#33245)

This commit is contained in:
Atif Shoukat Ali 2021-04-26 19:53:32 -07:00 committed by GitHub
parent 69bcaf9253
commit 408bc06bab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import { reduceField, ReducerID } from '..';
import { DataFrame, FieldType } from '../types/dataFrame';
import { DataFrameJSON } from './DataFrameJSON';
import { StreamingDataFrame } from './StreamingDataFrame';
@ -200,10 +201,14 @@ describe('Streaming JSON', () => {
maxLength: 5,
}
);
let val = reduceField({ field: stream.fields[0], reducers: [ReducerID.lastNotNull] })[ReducerID.lastNotNull];
expect(val).toEqual(100);
expect(stream.length).toEqual(1);
stream.push({
data: { values: [[200]] },
});
val = reduceField({ field: stream.fields[0], reducers: [ReducerID.lastNotNull] })[ReducerID.lastNotNull];
expect(val).toEqual(200);
expect(stream.length).toEqual(2);
const copy = ({ ...stream } as any) as DataFrame;

View File

@ -178,7 +178,11 @@ export class StreamingDataFrame implements DataFrame {
let appended = circPush(curValues, values, this.options.maxLength, this.timeFieldIndex, this.options.maxDelta);
appended.forEach((v, i) => {
this.fields[i].values.buffer = v;
const { state, values } = this.fields[i];
values.buffer = v;
if (state) {
state.calcs = undefined;
}
});
// Update the frame length

View File

@ -46,6 +46,8 @@ interface ReduceFieldOptions {
/**
* @returns an object with a key for each selected stat
* NOTE: This will also modify the 'field.state' object,
* leaving values in a cache until cleared.
*/
export function reduceField(options: ReduceFieldOptions): FieldCalcs {
const { field, reducers } = options;