Transformations: Fix inner join by field for zero-length frames (#93144)

pull/92970/head^2
Leon Sorokin 8 months ago committed by GitHub
parent 644a315667
commit f650a17030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 59
      packages/grafana-data/src/transformations/transformers/joinDataFrames.test.ts
  2. 3
      packages/grafana-data/src/transformations/transformers/joinDataFrames.ts

@ -280,6 +280,65 @@ describe('align frames', () => {
]
`);
});
it('should perform an inner join with empty values', () => {
const out = joinDataFrames({
frames: [
toDataFrame({
fields: [
{
name: 'A',
type: FieldType.string,
values: [],
},
{
name: 'B',
type: FieldType.string,
values: [],
},
],
}),
toDataFrame({
fields: [
{
name: 'A',
type: FieldType.string,
values: [],
},
{
name: 'C',
type: FieldType.string,
values: [],
},
],
}),
],
joinBy: fieldMatchers.get(FieldMatcherID.byName).get('A'),
mode: JoinMode.inner,
})!;
expect(
out.fields.map((f) => ({
name: f.name,
values: f.values,
}))
).toMatchInlineSnapshot(`
[
{
"name": "A",
"values": [],
},
{
"name": "B",
"values": [],
},
{
"name": "C",
"values": [],
},
]
`);
});
});
it('unsorted input keep indexes', () => {

@ -424,7 +424,8 @@ function joinInner(tables: AlignedData[]): Array<Array<string | number | null |
// Check if joinedTables is empty before transposing. No need to transpose if there are no joined tables.
if (joinedTables.length === 0) {
return [];
const fieldCount = tables.reduce((count, table) => count + (table.length - 1), 1);
return Array.from({ length: fieldCount }, () => []);
}
// Transpose the joined tables to get the desired output format.

Loading…
Cancel
Save