@@ -16,11 +16,11 @@ isrevertible(p::Parallel) = any(isrevertible, p.transforms)
16
16
function apply (p:: Parallel , table)
17
17
# apply transforms in parallel
18
18
f (transform) = apply (transform, table)
19
- result = foldxt (vcat, Map (f), p. transforms)
19
+ vals = foldxt (vcat, Map (f), p. transforms)
20
20
21
21
# retrieve tables and caches
22
- tables = first .(result )
23
- caches = last .(result )
22
+ tables = first .(vals )
23
+ caches = last .(vals )
24
24
25
25
# concatenate columns
26
26
allvars, allvals = [], []
@@ -43,49 +43,52 @@ function apply(p::Parallel, table)
43
43
𝒯 = (; zip (allvars, allvals)... )
44
44
newtable = 𝒯 |> Tables. materializer (table)
45
45
46
+ # save original column names
47
+ onames = Tables. columnnames (table)
48
+
46
49
# find first revertible transform
47
50
ind = findfirst (isrevertible, p. transforms)
48
51
49
- # save cache if any transform is revertible
50
- if isnothing (ind)
51
- cache = nothing
52
+ # save info to revert transform
53
+ rinfo = if isnothing (ind)
54
+ nothing
52
55
else
53
- onames = Tables. columnnames (table)
54
56
tnames = Tables. columnnames .(tables)
55
57
ncols = length .(tnames)
56
- rcache = caches[ind]
57
58
nrcols = ncols[ind]
58
59
start = sum (ncols[1 : ind- 1 ]) + 1
59
60
finish = start + nrcols - 1
60
- range = ( start, finish)
61
- cache = (ind, range, rcache, onames )
61
+ range = start: finish
62
+ (ind, range)
62
63
end
63
64
64
- newtable, cache
65
+ newtable, (onames, caches, rinfo)
65
66
end
66
67
67
68
function revert (p:: Parallel , newtable, cache)
68
- # sanity checks
69
- @assert ! isnothing (cache) " transform is not revertible"
69
+ # retrieve cache
70
+ onames = cache[1 ]
71
+ caches = cache[2 ]
72
+ rinfo = cache[3 ]
73
+
74
+ @assert ! isnothing (rinfo) " transform is not revertible"
70
75
71
- # retrieve subtable range and cache
72
- ind = cache[1 ]
73
- range = cache[2 ]
74
- rcache = cache[3 ]
75
- onames = cache[4 ]
76
- start, finish = range
76
+ # retrieve info to revert transform
77
+ ind = rinfo[1 ]
78
+ range = rinfo[2 ]
79
+ rtrans = p. transforms[ind]
80
+ rcache = caches[ind]
77
81
78
82
# columns of transformed table
79
83
cols = Tables. columns (newtable)
80
84
81
- # retrieve subtable for revert transform
82
- rcols = [Tables. getcolumn (cols, j) for j in start : finish ]
85
+ # retrieve subtable to revert
86
+ rcols = [Tables. getcolumn (cols, j) for j in range ]
83
87
𝒯 = (; zip (onames, rcols)... )
84
88
rtable = 𝒯 |> Tables. materializer (newtable)
85
89
86
90
# revert transform on subtable
87
- rtransform = p. transforms[ind]
88
- revert (rtransform, rtable, rcache)
91
+ revert (rtrans, rtable, rcache)
89
92
end
90
93
91
94
"""
0 commit comments