Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Hash-join/Go/hash-join.go
Normal file
31
Task/Hash-join/Go/hash-join.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
tableA := []struct {
|
||||
value int
|
||||
key string
|
||||
}{
|
||||
{27, "Jonah"}, {18, "Alan"}, {28, "Glory"}, {18, "Popeye"},
|
||||
{28, "Alan"},
|
||||
}
|
||||
tableB := []struct {
|
||||
key string
|
||||
value string
|
||||
}{
|
||||
{"Jonah", "Whales"}, {"Jonah", "Spiders"},
|
||||
{"Alan", "Ghosts"}, {"Alan", "Zombies"}, {"Glory", "Buffy"},
|
||||
}
|
||||
// hash phase
|
||||
h := map[string][]int{}
|
||||
for i, r := range tableA {
|
||||
h[r.key] = append(h[r.key], i)
|
||||
}
|
||||
// join phase
|
||||
for _, x := range tableB {
|
||||
for _, a := range h[x.key] {
|
||||
fmt.Println(tableA[a], x)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue