FieldValues: Use plain arrays instead of Vector (part 2 of 2) (#66224)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Ryan McKinley
2023-04-14 07:03:45 -07:00
committed by GitHub
parent 6d53c87862
commit e65163ba4e
57 changed files with 374 additions and 448 deletions

View File

@@ -3,7 +3,6 @@ import { delay, take } from 'rxjs/operators';
import { createFetchResponse } from 'test/helpers/createFetchResponse';
import {
ArrayVector,
DataFrame,
DataFrameJSON,
DataSourceApi,
@@ -238,7 +237,7 @@ const expectDataFrameWithValues = ({ time, values }: { time: number[]; values: n
name: 'time',
state: null,
type: FieldType.time,
values: new ArrayVector(time),
values: time,
} as Field,
{
config: {},
@@ -246,7 +245,7 @@ const expectDataFrameWithValues = ({ time, values }: { time: number[]; values: n
name: 'value',
state: null,
type: FieldType.number,
values: new ArrayVector(values),
values: values,
} as Field,
],
length: values.length,

View File

@@ -1,6 +1,5 @@
import {
AbsoluteTimeRange,
ArrayVector,
FieldType,
Labels,
LogLevel,
@@ -322,12 +321,12 @@ describe('mergeLogsVolumeDataFrames', () => {
{
name: 'Time',
type: FieldType.time,
values: new ArrayVector([1, 2, 3]),
values: [1, 2, 3],
},
{
name: 'Value',
type: FieldType.number,
values: new ArrayVector([3, 3, 1]),
values: [3, 3, 1],
config: {
displayNameFromDS: 'info',
},
@@ -339,12 +338,12 @@ describe('mergeLogsVolumeDataFrames', () => {
{
name: 'Time',
type: FieldType.time,
values: new ArrayVector([1, 2, 3, 5]),
values: [1, 2, 3, 5],
},
{
name: 'Value',
type: FieldType.number,
values: new ArrayVector([1, 2, 3, 0]),
values: [1, 2, 3, 0],
config: {
displayNameFromDS: 'debug',
},
@@ -356,12 +355,12 @@ describe('mergeLogsVolumeDataFrames', () => {
{
name: 'Time',
type: FieldType.time,
values: new ArrayVector([1, 6]),
values: [1, 6],
},
{
name: 'Value',
type: FieldType.number,
values: new ArrayVector([2, 1]),
values: [2, 1],
config: {
displayNameFromDS: 'error',
},
@@ -385,12 +384,12 @@ describe('getLogsVolumeDimensions', () => {
{
name: 'time',
type: FieldType.time,
values: new ArrayVector([]),
values: [],
},
{
name: 'value',
type: FieldType.number,
values: new ArrayVector(values),
values: values,
},
],
});

View File

@@ -1,5 +1,4 @@
import {
ArrayVector,
DataFrame,
DataFrameJSON,
DataFrameView,
@@ -181,8 +180,8 @@ export class BlugeSearcher implements GrafanaSearcher {
// Append the raw values to the same array buffer
const length = frame.length + view.dataFrame.length;
for (let i = 0; i < frame.fields.length; i++) {
const values = (view.dataFrame.fields[i].values as ArrayVector).buffer;
values.push(...frame.fields[i].values.toArray());
const values = view.dataFrame.fields[i].values;
values.push(...frame.fields[i].values);
}
view.dataFrame.length = length;

View File

@@ -1,6 +1,5 @@
import {
toDataFrame,
ArrayVector,
DataFrame,
FieldType,
toDataFrameDTO,
@@ -344,6 +343,7 @@ describe('Prepare time series transformer', () => {
};
const frames = prepareTimeSeriesTransformer.transformer(config, ctx)(source);
expect(frames).toEqual([
toEquableDataFrame({
name: 'wants-to-be-many',
@@ -422,7 +422,6 @@ function toEquableDataFrame(source: any): DataFrame {
fields: source.fields.map((field: any) => {
return {
...field,
values: new ArrayVector(field.values),
config: {},
};
}),

View File

@@ -11,7 +11,6 @@ import {
FieldMatcherID,
Field,
MutableDataFrame,
ArrayVector,
} from '@grafana/data';
import { Labels } from 'app/types/unified-alerting-dto';
@@ -115,11 +114,11 @@ export function toTimeSeriesMulti(data: DataFrame[]): DataFrame[] {
fields: [
{
...timeField,
values: new ArrayVector(b.time),
values: b.time,
},
{
...field,
values: new ArrayVector(b.value),
values: b.value,
labels: b.labels,
},
],

View File

@@ -69,10 +69,7 @@ export function timeSeriesToTableTransform(options: TimeSeriesTableTransformerOp
};
refId2frameField[refId] = frameField;
// NOTE: MutableDataFrame.addField() makes copies, including any .values buffers
// since we do .values.add() later on the *originals*, we pass a custom MutableVectorCreator
// which will re-use the existing empty .values buffer by reference
const table = new MutableDataFrame(undefined, (buffer) => buffer ?? []);
const table = new MutableDataFrame();
for (const label of Object.values(labelFields)) {
table.addField(label);
}