Hash join: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 445: | Line 445: | ||
<lang Groovy> |
<lang Groovy> |
||
def hashJoin(s, r) { |
def hashJoin(s, r, col) { |
||
def hashed = s.groupBy { sItem -> sItem |
def hashed = s.groupBy { sItem -> sItem[col] } |
||
def q = [] as Set |
def q = [] as Set |
||
r.each { rItem -> |
r.each { rItem -> |
||
def join = hashed[rItem |
def join = hashed[rItem[col]] |
||
join.each { sItem -> |
join.each { sItem -> |
||
q << sItem.plus(rItem) |
q << sItem.plus(rItem) |
||
Line 476: | Line 476: | ||
[name: 'Glory', nemesis: 'Buffy']] |
[name: 'Glory', nemesis: 'Buffy']] |
||
hashJoin(s, r).sort {it.name}.each { println it } |
hashJoin(s, r, "name").sort {it.name}.each { println it } |
||
</pre> |
</pre> |
||