Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Hash-join/Julia/hash-join-1.julia
Normal file
8
Task/Hash-join/Julia/hash-join-1.julia
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using DataFrames
|
||||
|
||||
A = DataFrame(Age = [27, 18, 28, 18, 28], Name = ["Jonah", "Alan", "Glory", "Popeye", "Alan"])
|
||||
B = DataFrame(Name = ["Jonah", "Jonah", "Alan", "Alan", "Glory"],
|
||||
Nemesis = ["Whales", "Spiders", "Ghosts", "Zombies", "Buffy"])
|
||||
AB = join(A, B, on = :Name)
|
||||
|
||||
@show A B AB
|
||||
19
Task/Hash-join/Julia/hash-join-2.julia
Normal file
19
Task/Hash-join/Julia/hash-join-2.julia
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
function hashjoin(A::Array, ja::Int, B::Array, jb::Int)
|
||||
M = Dict(t[jb] => filter(l -> l[jb] == t[jb], B) for t in B)
|
||||
return collect([a, b] for a in A for b in get(M, a[ja], ()))
|
||||
end
|
||||
|
||||
table1 = [(27, "Jonah"),
|
||||
(18, "Alan"),
|
||||
(28, "Glory"),
|
||||
(18, "Popeye"),
|
||||
(28, "Alan")]
|
||||
table2 = [("Jonah", "Whales"),
|
||||
("Jonah", "Spiders"),
|
||||
("Alan", "Ghosts"),
|
||||
("Alan", "Zombies"),
|
||||
("Glory", "Buffy")]
|
||||
|
||||
for r in hashjoin(table1, 2, table2, 1)
|
||||
println(r)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue