3

I'm using the join function from clojure.set. join with two parameters is supposed to do a natural join.

Load it up:

user=> (use 'clojure.set)
nil

This makes sense -- if either side of a join has 0 rows, so should the result:

user=> (join [{:a 1 :b 2}] [])
#{} 

This also makes sense -- identically-named columns (all 0 of them :)) have the same value:

user=> (join [{:a 1 :b 2}] [{}])
#{{:a 1, :b 2}}

Same thing here:

user=> (join [{:a 1 :b 2}] [{:c 3}])        
#{{:c 3, :a 1, :b 2}}

But here I get lost:

user=> (join [{:a 1 :b 2}] [{:a 2 :b 1} {}])
#{}

I joined {:a 1 :b 2} to {} earlier, and got a row. What am I missing?

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192

1 Answers1

3

Depending on how you look at it, it's either a bug in join, or a bug in the calling code that treats {:a 2 :b 1} and {} as members of the same relation; I lean toward the latter.

Specifically why this is happening is that the intersection of keys of the two relations is calculated one time using the first map of each relation. That's also why you'd get different results if you swap the position of the two maps in the second relation.

Alex Taggart
  • 7,805
  • 28
  • 31