Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Hash-join/Groovy/hash-join-1.groovy
Normal file
15
Task/Hash-join/Groovy/hash-join-1.groovy
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
def hashJoin(table1, col1, table2, col2) {
|
||||
|
||||
def hashed = table1.groupBy { s -> s[col1] }
|
||||
|
||||
def q = [] as Set
|
||||
|
||||
table2.each { r ->
|
||||
def join = hashed[r[col2]]
|
||||
join.each { s ->
|
||||
q << s.plus(r)
|
||||
}
|
||||
}
|
||||
|
||||
q
|
||||
}
|
||||
8
Task/Hash-join/Groovy/hash-join-2.groovy
Normal file
8
Task/Hash-join/Groovy/hash-join-2.groovy
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
def hashJoin(table1, col1, table2, col2) {
|
||||
|
||||
def hashed = table1.groupBy { s -> s[col1] }
|
||||
|
||||
table2.collect { r ->
|
||||
hashed[r[col2]].collect { s -> s.plus(r) }
|
||||
}.flatten()
|
||||
}
|
||||
13
Task/Hash-join/Groovy/hash-join-3.groovy
Normal file
13
Task/Hash-join/Groovy/hash-join-3.groovy
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def s = [[age: 27, name: 'Jonah'],
|
||||
[age: 18, name: 'Alan'],
|
||||
[age: 28, name: 'Glory'],
|
||||
[age: 18, name: 'Popeye'],
|
||||
[age: 28, name: 'Alan']]
|
||||
|
||||
def r = [[name: 'Jonah', nemesis: 'Whales'],
|
||||
[name: 'Jonah', nemesis: 'Spiders'],
|
||||
[name: 'Alan', nemesis: 'Ghosts'],
|
||||
[name: 'Alan', nemesis: 'Zombies'],
|
||||
[name: 'Glory', nemesis: 'Buffy']]
|
||||
|
||||
hashJoin(s, "name", r, "name").sort {it.name}.each { println it }
|
||||
Loading…
Add table
Add a link
Reference in a new issue