Timeseries: move join field to index zero (#35217)

This commit is contained in:
Ryan McKinley 2021-06-03 16:05:08 -07:00 committed by GitHub
parent 1dc387536e
commit e1af571efd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -180,11 +180,11 @@ describe('align frames', () => {
`);
});
it('sort single frame', () => {
it('sort single frame as index zero', () => {
const series1 = toDataFrame({
fields: [
{ name: 'TheTime', type: FieldType.time, values: [6000, 2000, 1500] },
{ name: 'A1', type: FieldType.number, values: [1, 22, 15] },
{ name: 'TheTime', type: FieldType.time, values: [6000, 2000, 1500] },
],
});

View File

@ -78,6 +78,9 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
let frame = options.frames[0];
let frameCopy = frame;
const joinFieldMatcher = getJoinMatcher(options);
let joinIndex = frameCopy.fields.findIndex((f) => joinFieldMatcher(f, frameCopy, options.frames));
if (options.keepOriginIndices) {
frameCopy = {
...frame,
@ -95,10 +98,16 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
return copy;
}),
};
}
const joinFieldMatcher = getJoinMatcher(options);
const joinIndex = frameCopy.fields.findIndex((f) => joinFieldMatcher(f, frameCopy, options.frames));
// Make sure the join field is first
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 (joinIndex >= 0) {