stevendesu / jsindex

1 stars 0 forks source link

Merge did not function as expected #7

Closed stevendesu closed 5 years ago

stevendesu commented 5 years ago

CSV1:

pop,name,lat,lng,type
ams,"(Amsterdam, Netherlands)",52.30308,4.93789,1
arn,"(Stockholm, Sweden)",59.42273,17.91869,1
atl,"(Atlanta, GA)",33.75544,-84.39159,1
aza,"(Phoenix, AZ)",33.39554,-111.9723,1
bog,"(Bogota, Columbia)",4.64785,-74.07149,1
cdg,"(Paris, France)",48.85613,2.38354,1
dal,"(Dallas, TX)",32.80074,-96.81921,17
fll,"(Miami, FL)",25.77602,-80.19302,1
fra,"(Frankfurt, Germany)",50.11132,8.71743,1
iad,"(Ashburn, VA)",39.01621,-77.45929,1
lax,"(Los Angeles, CA)",34.0474,-118.25739,17
lcy,"(London, United Kingdom)",51.52023,-0.0731,1
lon,"(London, United Kingdom)",51.51158,-0.00273,1
phx,"(Tempe, AZ)",33.41407,-111.97354,1

CSV2:

id,apop,zpop,speed
0,ams,lcy,100000
1,ams,lon,100000
2,arn,ams,40000
3,arn,fra,40000
4,atl,dal,200000
5,aza,lax,100000
6,aza,phx,200000
7,bog,fll,10000
8,cdg,iad,40000

JavaScript:

const pops = Array.load(CSV1).index();
const links = Array.load(CSV2).index();

links.merge(pops, {joinOn: {left: "apop", right: "pop"}});
links.merge(pops, {joinOn: {left: "zpop", right: "pop"}});

Expected:

[
    ...
    {id: 4, apop: "atl", zpop: "dal", speed: 200000, name: "(Atlanta, GA)", "lat": 33.75544, "lng": -84.39159, "type": 1, "name_2": "(Dallas, TX)", "lat_2": 32.80074, "lng_2": -96.81921, "type_2": 17}
    ...
]

Actual:

[
    ...
    {id: 4, apop: "atl", zpop: "dal", speed: 200000, name: "(Atlanta, GA)", "lat": 33.75544, "lng": -84.39159, "type": 1, "name_2": "(Dallas, TX)", "lat_2": 32.80074, "lng_2": -96.81921, "type_2": 1}
    ...
]

The type_2 field is incorrect

As this is real-world data that didn't work, let's do proper TDD and build a test case using this exact data.

stevendesu commented 5 years ago

I may actually be experiencing two bugs. In my VueJS project I was receiving:

[
    ...
    {id: 4, apop: "atl", zpop: "dal", speed: 200000, name: null, "lat": null, "lng": null, "type": null, "name_2": null, "lat_2": null, "lng_2": null, "type_2": null}
    ...

This led me to create this issue and a test case. However in the test case the merge was a lot more effective, only getting a single type field wrong.

I'm not sure if these are two manifestations of the same bug, or two separate bugs.

stevendesu commented 5 years ago

Upon further research, I had mistyped my expected.json. The issue described does not repro using these CSVs and the code in this ticket.

I will have to do further investigation to figure out why the issue arises in my VueJS application.

stevendesu commented 5 years ago

I can't repro this even on my VueJS app. I'm going to guess I was having trouble with browser cache, my build tool, or some other step in the pipeline. This library works fine.