Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Hash-join/Scala/hash-join.scala
Normal file
19
Task/Hash-join/Scala/hash-join.scala
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
def join[Type](left: Seq[Seq[Type]], right: Seq[Seq[Type]]) = {
|
||||
val hash = right.groupBy(_.head) withDefaultValue Seq()
|
||||
left.flatMap(cols => hash(cols.last).map(cols ++ _.tail))
|
||||
}
|
||||
|
||||
// Example:
|
||||
|
||||
val table1 = List(List("27", "Jonah"),
|
||||
List("18", "Alan"),
|
||||
List("28", "Glory"),
|
||||
List("18", "Popeye"),
|
||||
List("28", "Alan"))
|
||||
val table2 = List(List("Jonah", "Whales"),
|
||||
List("Jonah", "Spiders"),
|
||||
List("Alan", "Ghosts"),
|
||||
List("Alan", "Zombies"),
|
||||
List("Glory", "Buffy"))
|
||||
|
||||
println(join(table1, table2) mkString "\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue