mirror of
https://github.com/grafana/grafana.git
synced 2024-12-28 18:01:40 -06:00
Transformations: Fix inner join by field for zero-length frames (#93144)
This commit is contained in:
parent
644a315667
commit
f650a17030
@ -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…
Reference in New Issue
Block a user