BurntSushi / xsv

A fast CSV command line toolkit written in Rust.
The Unlicense
10.29k stars 317 forks source link

Unintuitive no-headers join behaviour #254

Open tomarrell opened 3 years ago

tomarrell commented 3 years ago

Ran into some slightly unintuitive behaviour when misusing a join due to omission of the --no-headers flag.

When inputting two files, both without headers and trying to perform a join while forgetting the flag, the first result appears to be joined with a value that does not match. I've included a minimum reproducible example below.

input_1.csv

1,test1
2,test2
3,test3

input_2.csv

a,oops
b,test1
c,test2
d,test3

Running the command:

> xsv join 2 input_1.csv 2 input_2.csv
1,test1,a,oops
2,test2,c,test2
3,test3,d,test3

As you can see, the first row of the first input is joined with the first row of the second input – even though there is a valid join for the first row in the second input, on the second line.

This is slightly counter-intuitive behaviour even considering the omission of the --no-headers flag.

Intuitively, I would expect that even with omission of the flag, the following should be output.

1,test1,a,test1
2,test2,c,test2
3,test3,d,test3

Apologies if this comes across as a little nit picky, feel free to close it if there is a good reason not to have this behaviour that I'm missing.

Cheers!