Different (incorrect) results for sortedMergeInnerJoin vs. hashInnerJoin #43
Closed
Description
Hello!
Great library, very helpful to avoid having to implement SQL joins myself in Typescript. Smaller and easier to work with than AlaSQL.
Recently I was writing some tests for some joins I am doing with this library (installed via NPM) and found that sortedMergeInnerJoin is giving incorrect results.
Here is the code to reproduce:
const leftAccessor = (row: any) => {
return row["id"];
};
const rightAccessor = (row: any) => {
return row["id];
};
const left = [
{ id: 1, name: "John", sameColumn: "left", leftId: 1 },
{ id: 2, name: "Jane", sameColumn: "left", leftId: 2 },
{ id: "left", name: "Left", sameColumn: "left", leftId: "left" },
];
const right = [
{ id: 1, age: 20, sameColumn: "right", rightId: 1 },
{ id: 2, age: 30, sameColumn: "right", rightId: 2 },
{ id: "right", age: 1000, sameColumn: "right", rightId: "right" },
];
const results = sortedMergeInnerJoin(left, leftAccessor, right, rightAccessor);
This is producing:
[
{
id: 1,
name: 'John',
sameColumn: 'right',
leftId: 1,
age: 20,
rightId: 1
},
{
id: 2,
name: 'Left',
sameColumn: 'right',
leftId: 'left',
age: 30,
rightId: 2
}
]
, instead of expected:
[
{
id: 1,
name: 'John',
sameColumn: 'right',
leftId: 1,
age: 20,
rightId: 1
},
{
id: 2,
name: 'Jane',
sameColumn: 'right',
leftId: 2,
age: 30,
rightId: 2
}
]
It looks like the expected join is returned by hashInnerJoin.
Metadata
Assignees
Labels
No labels