(join xrel yrel)
(join xrel yrel km)
When passed 2 rels, returns the rel corresponding to the natural
join. When passed an additional keymap, joins on the corresponding
keys.
Source
(defn
join
"When passed 2 rels, returns the rel corresponding to the natural\n join. When passed an additional keymap, joins on the corresponding\n keys."
([xrel yrel]
(if
(and (seq xrel) (seq yrel))
(let
[ks
(intersection (set (keys (first xrel))) (set (keys (first yrel))))
[r s]
(if (<= (count xrel) (count yrel)) [xrel yrel] [yrel xrel])
idx
(index r ks)]
(reduce
(fn
[ret x]
(let
[found (idx (select-keys x ks))]
(if
found
(reduce
(fn*
[p1__18460# p2__18461#]
(conj p1__18460# (merge p2__18461# x)))
ret
found)
ret)))
#{}
s))
#{}))
([xrel yrel km]
(let
[[r s k]
(if
(<= (count xrel) (count yrel))
[xrel yrel (map-invert km)]
[yrel xrel km])
idx
(index r (vals k))]
(reduce
(fn
[ret x]
(let
[found (idx (rename-keys (select-keys x (keys k)) k))]
(if
found
(reduce
(fn*
[p1__18462# p2__18463#]
(conj p1__18462# (merge p2__18463# x)))
ret
found)
ret)))
#{}
s))))