Skip to content

Commit 30a83e6

Browse files
committed
Add reapply for Parallel
1 parent 4e6f097 commit 30a83e6

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

src/transforms/parallel.jl

+39-19
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,8 @@ function apply(p::Parallel, table)
2222
tables = first.(vals)
2323
caches = last.(vals)
2424

25-
# concatenate columns
26-
allvars, allvals = [], []
27-
varsdict = Set{Symbol}()
28-
for 𝒯 in tables
29-
cols = Tables.columns(𝒯)
30-
vars = Tables.columnnames(𝒯)
31-
vals = [Tables.getcolumn(cols, var) for var in vars]
32-
for (var, val) in zip(vars, vals)
33-
while var varsdict
34-
var = Symbol(var,:_)
35-
end
36-
push!(varsdict, var)
37-
push!(allvars, var)
38-
push!(allvals, val)
39-
end
40-
end
41-
4225
# table with concatenated columns
43-
𝒯 = (; zip(allvars, allvals)...)
44-
newtable = 𝒯 |> Tables.materializer(table)
26+
newtable = tablehcat(tables)
4527

4628
# save original column names
4729
onames = Tables.columnnames(table)
@@ -91,6 +73,44 @@ function revert(p::Parallel, newtable, cache)
9173
revert(rtrans, rtable, rcache)
9274
end
9375

76+
function reapply(p::Parallel, table, cache)
77+
# retrieve caches
78+
caches = cache[2]
79+
80+
# reapply transforms in parallel
81+
f((t,c)) = reapply(t, table, c) |> first
82+
itr = zip(p.transforms, caches)
83+
tables = foldxt(vcat, Map(f), itr)
84+
85+
# table with concatenated columns
86+
newtable = tablehcat(tables)
87+
88+
newtable, cache
89+
end
90+
91+
function tablehcat(tables)
92+
# concatenate columns
93+
allvars, allvals = [], []
94+
varsdict = Set{Symbol}()
95+
for 𝒯 in tables
96+
cols = Tables.columns(𝒯)
97+
vars = Tables.columnnames(𝒯)
98+
vals = [Tables.getcolumn(cols, var) for var in vars]
99+
for (var, val) in zip(vars, vals)
100+
while var varsdict
101+
var = Symbol(var,:_)
102+
end
103+
push!(varsdict, var)
104+
push!(allvars, var)
105+
push!(allvals, val)
106+
end
107+
end
108+
109+
# table with concatenated columns
110+
𝒯 = (; zip(allvars, allvals)...)
111+
𝒯 |> Tables.materializer(first(tables))
112+
end
113+
94114
"""
95115
transform₁ ⊔ transform₂ ⊔ ⋯ ⊔ transformₙ
96116

0 commit comments

Comments
 (0)