-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FieldValues: Use plain arrays instead of Vector (part 1 of 2) #66187
Conversation
(Open the links below in a new tab to go to the correct steps)
|
Fix flaky unit test
…and name matchers (#65237) Co-authored-by: Brendan O'Handley <brendan.ohandley@grafana.com>
return this.buffer; | ||
constructor(buffer?: T[]) { | ||
super(); | ||
this.buffer = buffer ?? []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this now shallow-copies (via setter) the passed-in buffer rather than absorbing it by reference. we can't avoid this since ArrayVector now extends Array, . this new behavior required fixes in two places which had these buffer pre-allocation/mutation patterns:
- pre-allocate a buffer via
let buf = new Array(10)
- wrap it with
field.values = ArrayVector(buf)
- mutate the buffer expecting it to reflect in
field.values
viabuf[i] = 100
- Create a new mutable frame:
let mutFrame = new MutableDataFrame()
; - Create some field:
let field = {name: 'a', values: new ArrayVector()}
- Add field:
mutFrame.addField(field)
(this shallow copies field internally, and wraps .values buffers in ArrayVector) - Try to add values to the field, expecting the values to change in the mutable frame field's copy:
field.values.add("a")
Backend code coverage report for PR #66187 |
Frontend code coverage report for PR #66187
|
expect(result.fields[0].values.toArray()).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
expect(result.fields[1].values.toArray()).toStrictEqual([4, null, 6, null, null, null, null, null, null, 8]); | ||
expect(result.fields[2].values.toArray()).toStrictEqual(['a', null, 'b', null, null, null, null, null, null, 'c']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: all the .toArray()
removals in this PR are not essential to get the tests passing; they're just drive-by simplifications that can technically be pulled into Part 2: #66224
the key changes here are the .toStrictEqual() -> .toEqual()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loki part looks good 👍
What is this feature?
This adds basic basic functions to the existing Vector interface. This will allow Vector and normal arrays to share more of the the same key types.
This is technically a breaking change because we are requiring new functions on an interface -- however it would be an extremely esoteric use case to implement the Vector interface directly rather than use one of the existing implementaions.
Why do we need this feature?
Ideally the
frame.fields[idx].values
element would be a simple arrary... however we originally used apache arrow in the frontend, and it required an accessor function. It seemed ok at the time, but is really a mess and pretty confusing.In 10, we would like to support using values as either a simple array or Vector. This PR helps unify the typing requirements so we do not need to check
isArray(vector)
all the timeWho is this feature for?
Developers
Special notes for your reviewer:
Please check that:
Release notice breaking change
Additional functions (map/filter/forEach/iterator) have been added to the root Vector interface. Any code using vectors will continue to work unchanged, but in the rare case that you have implemented Vector directly, it be missing these functions. The easiest fix is to extend FunctionalVector.
The
ArrayVector
class now extends the native JavaScriptArray
and gains all of its prototype/instance methods as a result.