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

This commit is contained in:
Leon Sorokin 2024-09-09 21:22:03 -05:00 committed by GitHub
parent 644a315667
commit f650a17030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 1 deletions

View File

@ -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', () => { it('unsorted input keep indexes', () => {

View File

@ -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. // Check if joinedTables is empty before transposing. No need to transpose if there are no joined tables.
if (joinedTables.length === 0) { 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. // Transpose the joined tables to get the desired output format.