stevendesu / jsindex

1 stars 0 forks source link

Array merge method does not copy indexes from right-hand side #3

Open stevendesu opened 5 years ago

stevendesu commented 5 years ago

I currently have a project with the following collections / arrays:

I wanted to merge all three of these collections together so that for a given account I could find all data centers where traffic was delivered, or for a given data center I could find all accounts delivering traffic:

const data = Array.load(datacenterCsv, {sync: true}).index();
const accounts = Array.load(accountsCsv, {sync: true}).index();
const traffic = Array.load(trafficCsv, {sync: true}).index();

data.merge(trafffic, { joinOn: { left: "id", right: "datacenter" } });
data.merge(accounts, { joinOn: { left: "account", right: "id" } });

This failed because even though traffic was indexed on account, the merged collection did not have this index.

Retaining these indexes may hurt the performance of merging somewhat, but will enable changed merges like this. Because of the possible performance hit, I may consider making it an option:

data.merge(traffic, { joinOn: { left: "id", right: "datacenter" }, copyIndex: true });

This way people can opt in (or out if I make it a default) depending on whether they need this functionality.

Whichever solution I choose, this isn't a breaking change (just a new option and a modification to the implementation) so it will only be a bump to 0.1.1 or similar.