mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Timeseries: move join field to index zero (#35217)
This commit is contained in:
parent
1dc387536e
commit
e1af571efd
@ -180,11 +180,11 @@ describe('align frames', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sort single frame', () => {
|
it('sort single frame as index zero', () => {
|
||||||
const series1 = toDataFrame({
|
const series1 = toDataFrame({
|
||||||
fields: [
|
fields: [
|
||||||
{ name: 'TheTime', type: FieldType.time, values: [6000, 2000, 1500] },
|
|
||||||
{ name: 'A1', type: FieldType.number, values: [1, 22, 15] },
|
{ name: 'A1', type: FieldType.number, values: [1, 22, 15] },
|
||||||
|
{ name: 'TheTime', type: FieldType.time, values: [6000, 2000, 1500] },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -78,6 +78,9 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
|
|||||||
let frame = options.frames[0];
|
let frame = options.frames[0];
|
||||||
let frameCopy = frame;
|
let frameCopy = frame;
|
||||||
|
|
||||||
|
const joinFieldMatcher = getJoinMatcher(options);
|
||||||
|
let joinIndex = frameCopy.fields.findIndex((f) => joinFieldMatcher(f, frameCopy, options.frames));
|
||||||
|
|
||||||
if (options.keepOriginIndices) {
|
if (options.keepOriginIndices) {
|
||||||
frameCopy = {
|
frameCopy = {
|
||||||
...frame,
|
...frame,
|
||||||
@ -95,10 +98,16 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
|
|||||||
return copy;
|
return copy;
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const joinFieldMatcher = getJoinMatcher(options);
|
// Make sure the join field is first
|
||||||
const joinIndex = frameCopy.fields.findIndex((f) => joinFieldMatcher(f, frameCopy, options.frames));
|
if (joinIndex > 0) {
|
||||||
|
const joinField = frameCopy.fields[joinIndex];
|
||||||
|
const fields = frameCopy.fields.filter((f, idx) => idx !== joinIndex);
|
||||||
|
fields.unshift(joinField);
|
||||||
|
frameCopy.fields = fields;
|
||||||
|
joinIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (options.enforceSort) {
|
if (options.enforceSort) {
|
||||||
if (joinIndex >= 0) {
|
if (joinIndex >= 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user