1
1
2
- function select_rowfunction (row, mappable_part_of_normalized_cs, colresults )
2
+ function select_rowfunction (row, mappable_part_of_normalized_cs)
3
3
_cs = [
4
4
begin
5
5
kk = result_colname === AsTable ? Symbol (" AsTable$(i) " ) : result_colname
@@ -21,8 +21,6 @@ function select_rowfunction(row, mappable_part_of_normalized_cs, colresults)
21
21
f. fun (args)
22
22
elseif f == identity
23
23
args
24
- elseif length (colresults[i]) == 1
25
- colresults[i]
26
24
else
27
25
throw (ErrorException (" Weird unhandled stuff" ))
28
26
end
@@ -33,62 +31,106 @@ function select_rowfunction(row, mappable_part_of_normalized_cs, colresults)
33
31
return (; _cs... )
34
32
end
35
33
36
- function fillcolumns (
37
- dt:: DTable , ics:: Dict{Int,Any} , normalized_cs, chunk_lengths_of_original_dt:: Vector{Int}
34
+ function fillcolumn (
35
+ chunk,
36
+ csymbols:: Union{Vector{DataType},Vector{Symbol},Vector{Union{DataType,Symbol}}} ,
37
+ colfragments:: Union{Vector{Dagger.EagerThunk},Vector{Any}} ,
38
+ expected_chunk_length:: Int ,
39
+ normalized_cs:: Vector{Any} ,
38
40
)
39
- col_keys_indices = collect (keys (ics)):: Vector{Int}
40
- col_vecs = map (x -> ics[x], col_keys_indices):: Union{Vector{Any},Vector{Dagger.EagerThunk}}
41
-
42
- f =
43
- (ch, csymbols, colfragments) -> begin
44
- col_vecs_fetched = fetch .(colfragments)
45
- colnames = Vector {Symbol} ()
46
- cols = Vector {Any} ()
47
- last_astable = 0
41
+ col_vecs_fetched = fetch .(colfragments)
42
+ colnames = Vector {Symbol} ()
43
+ cols = Vector {Any} ()
44
+ last_astable = 0
48
45
49
- for (idx, (_, (_, sym))) in enumerate (normalized_cs)
50
- if sym != = AsTable
51
- col = if sym in csymbols
52
- index = something (indexin (csymbols, [sym])... )
53
- col_vecs_fetched[index]
54
- else
55
- getcolumn (ch, sym)
56
- end
57
- push! (colnames, sym)
58
- push! (cols, col)
59
- elseif sym === AsTable
60
- i = findfirst (x -> x === AsTable, csymbols[(last_astable + 1 ): end ])
61
- if i === nothing
62
- c = getcolumn (ch, Symbol (" AsTable$(idx) " ))
63
- else
64
- last_astable = i
65
- c = col_vecs_fetched[i]
66
- end
67
-
68
- push! .(Ref (colnames), columnnames (columns (c)))
69
- push! .(Ref (cols), getcolumn .(Ref (columns (c)), columnnames (columns (c))))
46
+ for (idx, (_, (_, sym))) in enumerate (normalized_cs)
47
+ if sym != = AsTable
48
+ col = if sym in csymbols
49
+ index = findfirst (x -> x === sym, csymbols)
50
+ if col_vecs_fetched[index] isa AbstractVector
51
+ col_vecs_fetched[index]
52
+ else
53
+ repeat ([col_vecs_fetched[index]], expected_chunk_length)
54
+ end
55
+ else
56
+ getcolumn (chunk, sym)
57
+ end
58
+ push! (colnames, sym)
59
+ push! (cols, col)
60
+ elseif sym === AsTable
61
+ i = findfirst (x -> x === AsTable, csymbols[(last_astable + 1 ): end ])
62
+ c = if i === nothing
63
+ getcolumn (chunk, Symbol (" AsTable$(idx) " ))
64
+ else
65
+ last_astable = i
66
+ if col_vecs_fetched[i] isa AbstractVector
67
+ col_vecs_fetched[i]
70
68
else
71
- throw ( ErrorException ( " something is off " ) )
69
+ repeat ([col_vecs_fetched[i]], expected_chunk_length )
72
70
end
73
71
end
74
- materializer (ch)(
75
- merge (NamedTuple (), (; [e[1 ] => e[2 ] for e in zip (colnames, cols)]. .. ))
76
- )
72
+
73
+ push! .(Ref (colnames), columnnames (columns (c)))
74
+ push! .(Ref (cols), getcolumn .(Ref (columns (c)), columnnames (columns (c))))
75
+ else
76
+ throw (ErrorException (" something is off" ))
77
77
end
78
+ end
79
+ return materializer (chunk)(
80
+ merge (NamedTuple (), (; [e[1 ] => e[2 ] for e in zip (colnames, cols)]. .. ))
81
+ )
82
+ end
83
+
84
+ function fillcolumns (
85
+ dt:: Union{Nothing,DTable} ,
86
+ normalized_cs_results:: Dict{Int,Dagger.EagerThunk} ,
87
+ normalized_cs:: Vector{Any} ,
88
+ new_chunk_lengths:: Vector{Int} ,
89
+ fullcolumn_ops_result_lengths:: Vector{Int} ,
90
+ )
91
+ fullcolumn_ops_indices_in_normalized_cs = collect (keys (normalized_cs_results)):: Vector{Int}
92
+ fullcolumn_ops_results_ordered = map (
93
+ x -> normalized_cs_results[x], fullcolumn_ops_indices_in_normalized_cs
94
+ ):: Union{Vector{Any},Vector{Dagger.EagerThunk}}
78
95
79
96
colfragment = (column, s, e) -> Dagger. @spawn getindex (column, s: e)
80
- clenghts = chunk_lengths_of_original_dt
81
- result_column_symbols = getindex .(Ref (map (x -> x[2 ][2 ], normalized_cs)), col_keys_indices )
97
+ result_column_symbols =
98
+ getindex .(Ref (map (x -> x[2 ][2 ], normalized_cs)), fullcolumn_ops_indices_in_normalized_cs )
82
99
83
- chunks = [
84
- begin
85
- cfrags = [
86
- colfragment (column, 1 + sum (clenghts[ 1 : (i - 1 )]), sum (clenghts[ 1 : i])) for
87
- column in col_vecs
88
- ]
89
- Dagger. @ spawn f (ch, result_column_symbols, cfrags)
90
- end for (i, ch) in enumerate (dt . chunks )
100
+ dtchunks = if dt === nothing
101
+ [Dagger . spawn (() -> nothing ) for _ in 1 : length (new_chunk_lengths)]
102
+ else
103
+ dt . chunks
104
+ end
105
+ dtchunks_filled = [
106
+ x <= length (dtchunks) ? dtchunks[x] : Dagger. spawn (() -> nothing ) for
107
+ x in 1 : length (new_chunk_lengths )
91
108
]
92
109
93
- return DTable (chunks, dt. tabletype)
110
+ chunks = Dagger. EagerThunk[
111
+ Dagger. spawn (
112
+ fillcolumn,
113
+ chunk,
114
+ result_column_symbols,
115
+ [
116
+ if len > 1
117
+ colfragment (
118
+ column, 1 + sum (new_chunk_lengths[1 : (i - 1 )]), sum (new_chunk_lengths[1 : i])
119
+ )
120
+ else
121
+ column
122
+ end for
123
+ (column, len) in zip (fullcolumn_ops_results_ordered, fullcolumn_ops_result_lengths)
124
+ ],
125
+ new_chunk_length,
126
+ normalized_cs,
127
+ ) for
128
+ (i, (chunk, new_chunk_length)) in enumerate (zip (dtchunks_filled, new_chunk_lengths)) if
129
+ new_chunk_length > 0
130
+ ]
131
+ if dt === nothing
132
+ return DTable (chunks, nothing )
133
+ else
134
+ return DTable (chunks, dt. tabletype)
135
+ end
94
136
end
0 commit comments