mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FieldValues: Use plain arrays instead of Vector (part 1 of 2) (#66187)
Co-authored-by: Leon Sorokin <leeoniya@gmail.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
@@ -300,17 +300,13 @@ describe('LiveDataStream', () => {
|
||||
config: {},
|
||||
name: 'time',
|
||||
type: 'time',
|
||||
values: {
|
||||
buffer: [100, 101],
|
||||
},
|
||||
values: [100, 101],
|
||||
},
|
||||
{
|
||||
config: {},
|
||||
name: 'b',
|
||||
type: 'number',
|
||||
values: {
|
||||
buffer: [1, 2],
|
||||
},
|
||||
values: [1, 2],
|
||||
},
|
||||
]);
|
||||
expect(deserializedFrame.length).toEqual(dataFrameJsons.schema1().data.values[0].length);
|
||||
@@ -529,17 +525,13 @@ describe('LiveDataStream', () => {
|
||||
config: {},
|
||||
name: 'time',
|
||||
type: 'time',
|
||||
values: {
|
||||
buffer: [100, 101],
|
||||
},
|
||||
values: [100, 101],
|
||||
},
|
||||
{
|
||||
config: {},
|
||||
name: 'b',
|
||||
type: 'number',
|
||||
values: {
|
||||
buffer: [1, 2],
|
||||
},
|
||||
values: [1, 2],
|
||||
},
|
||||
]);
|
||||
expect(deserializedFrame.length).toEqual(dataFrameJsons.schema1().data.values[0].length);
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('Streaming JSON', () => {
|
||||
});
|
||||
|
||||
it('should create frame with schema & data', () => {
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values.buffer }))).toMatchInlineSnapshot(`
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values }))).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "time",
|
||||
@@ -127,7 +127,7 @@ describe('Streaming JSON', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values.buffer }))).toMatchInlineSnapshot(`
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values }))).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "time",
|
||||
@@ -167,7 +167,7 @@ describe('Streaming JSON', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values.buffer }))).toMatchInlineSnapshot(`
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values }))).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "time",
|
||||
@@ -211,7 +211,7 @@ describe('Streaming JSON', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values.buffer }))).toMatchInlineSnapshot(`
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values }))).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "time",
|
||||
@@ -263,7 +263,7 @@ describe('Streaming JSON', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values.buffer }))).toMatchInlineSnapshot(`
|
||||
expect(stream.fields.map((f) => ({ name: f.name, value: f.values }))).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "time",
|
||||
@@ -558,7 +558,7 @@ describe('Streaming JSON', () => {
|
||||
[10, 11],
|
||||
]);
|
||||
expect(frame.length).toEqual(3);
|
||||
expect(frame.fields.map((f) => ({ name: f.name, value: f.values.buffer }))).toMatchInlineSnapshot(`
|
||||
expect(frame.fields.map((f) => ({ name: f.name, value: f.values }))).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "time",
|
||||
@@ -603,7 +603,7 @@ describe('Streaming JSON', () => {
|
||||
[10, 11],
|
||||
]);
|
||||
expect(frame.length).toEqual(2);
|
||||
expect(frame.fields.map((f) => ({ name: f.name, value: f.values.buffer }))).toMatchInlineSnapshot(`
|
||||
expect(frame.fields.map((f) => ({ name: f.name, value: f.values }))).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "time",
|
||||
@@ -720,7 +720,7 @@ describe('Streaming JSON', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(stream.fields.map((f) => ({ name: f.name, labels: f.labels, values: f.values.buffer })))
|
||||
expect(stream.fields.map((f) => ({ name: f.name, labels: f.labels, values: f.values })))
|
||||
.toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
@@ -854,7 +854,7 @@ describe('Streaming JSON', () => {
|
||||
|
||||
const getSnapshot = (f: StreamingDataFrame) => {
|
||||
return {
|
||||
values: f.fields[1].values.toArray(),
|
||||
values: f.fields[1].values,
|
||||
info: f.packetInfo,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
ArrayVector,
|
||||
DataFrame,
|
||||
DataFrameJSON,
|
||||
decodeFieldValueEntities,
|
||||
@@ -60,7 +59,7 @@ export class StreamingDataFrame implements DataFrame {
|
||||
refId?: string;
|
||||
meta: QueryResultMeta = {};
|
||||
|
||||
fields: Array<Field<any, ArrayVector<any>>> = [];
|
||||
fields: Field[] = [];
|
||||
length = 0;
|
||||
|
||||
private schemaFields: FieldSchema[] = [];
|
||||
@@ -146,11 +145,11 @@ export class StreamingDataFrame implements DataFrame {
|
||||
...f,
|
||||
type: f.type ?? FieldType.other,
|
||||
config: f.config ?? {},
|
||||
values: Array.isArray(f.values) ? new ArrayVector(f.values) : new ArrayVector(),
|
||||
values: f.values ?? [],
|
||||
}));
|
||||
|
||||
assureValuesAreWithinLengthLimit(
|
||||
this.fields.map((f) => f.values.buffer),
|
||||
this.fields.map((f) => f.values),
|
||||
this.options.maxLength,
|
||||
this.timeFieldIndex,
|
||||
this.options.maxDelta
|
||||
@@ -256,8 +255,8 @@ export class StreamingDataFrame implements DataFrame {
|
||||
// transfer old values by type & name, unless we relied on labels to match fields
|
||||
values: isWide
|
||||
? this.fields.find((of) => of.name === f.name && f.type === of.type)?.values ??
|
||||
new ArrayVector(Array(this.length).fill(undefined))
|
||||
: new ArrayVector(),
|
||||
Array(this.length).fill(undefined)
|
||||
: [],
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -322,7 +321,7 @@ export class StreamingDataFrame implements DataFrame {
|
||||
name,
|
||||
type,
|
||||
config: {},
|
||||
values: new ArrayVector([]),
|
||||
values: [],
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -336,13 +335,14 @@ export class StreamingDataFrame implements DataFrame {
|
||||
this.packetInfo.action = StreamingFrameAction.Append;
|
||||
|
||||
// mutates appended
|
||||
appended = this.fields.map((f) => f.values.buffer);
|
||||
appended = this.fields.map((f) => f.values);
|
||||
circPush(appended, values, this.options.maxLength, this.timeFieldIndex, this.options.maxDelta);
|
||||
}
|
||||
|
||||
appended.forEach((v, i) => {
|
||||
const { state, values } = this.fields[i];
|
||||
values.buffer = v;
|
||||
const field = this.fields[i];
|
||||
const { state } = field;
|
||||
field.values = v;
|
||||
if (state) {
|
||||
state.calcs = undefined;
|
||||
}
|
||||
@@ -369,7 +369,7 @@ export class StreamingDataFrame implements DataFrame {
|
||||
|
||||
if (this.options.action === StreamingFrameAction.Append) {
|
||||
circPush(
|
||||
this.fields.map((f) => f.values.buffer),
|
||||
this.fields.map((f) => f.values),
|
||||
values,
|
||||
this.options.maxLength,
|
||||
this.timeFieldIndex,
|
||||
@@ -377,19 +377,19 @@ export class StreamingDataFrame implements DataFrame {
|
||||
);
|
||||
} else {
|
||||
values.forEach((v, i) => {
|
||||
if (this.fields[i]?.values) {
|
||||
this.fields[i].values.buffer = v;
|
||||
if (this.fields[i]) {
|
||||
this.fields[i].values = v;
|
||||
}
|
||||
});
|
||||
|
||||
assureValuesAreWithinLengthLimit(
|
||||
this.fields.map((f) => f.values.buffer),
|
||||
this.fields.map((f) => f.values),
|
||||
this.options.maxLength,
|
||||
this.timeFieldIndex,
|
||||
this.options.maxDelta
|
||||
);
|
||||
}
|
||||
const newLength = this.fields?.[0]?.values?.buffer?.length;
|
||||
const newLength = this.fields?.[0]?.values.length;
|
||||
if (newLength !== undefined) {
|
||||
this.length = newLength;
|
||||
}
|
||||
@@ -412,7 +412,7 @@ export class StreamingDataFrame implements DataFrame {
|
||||
|
||||
getValuesFromLastPacket = (): unknown[][] =>
|
||||
this.fields.map((f) => {
|
||||
const values = f.values.buffer;
|
||||
const values = f.values;
|
||||
return values.slice(Math.max(values.length - this.packetInfo.length));
|
||||
});
|
||||
|
||||
@@ -449,7 +449,7 @@ export class StreamingDataFrame implements DataFrame {
|
||||
...proto,
|
||||
config,
|
||||
labels: parsedLabels,
|
||||
values: new ArrayVector(Array(this.length).fill(undefined)),
|
||||
values: Array(this.length).fill(undefined),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,25 +99,19 @@ describe('GrafanaLiveService', () => {
|
||||
config: {},
|
||||
name: 'time',
|
||||
type: FieldType.time,
|
||||
values: {
|
||||
buffer: [100, 101],
|
||||
},
|
||||
values: [100, 101],
|
||||
},
|
||||
{
|
||||
config: {},
|
||||
name: 'a',
|
||||
type: FieldType.string,
|
||||
values: {
|
||||
buffer: ['a', 'b'],
|
||||
},
|
||||
values: ['a', 'b'],
|
||||
},
|
||||
{
|
||||
config: {},
|
||||
name: 'b',
|
||||
type: FieldType.number,
|
||||
values: {
|
||||
buffer: [1, 2],
|
||||
},
|
||||
values: [1, 2],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user