@@ -22,6 +22,13 @@ function __init__()
22
22
allocatecolumn (:: Type{WeakRefString{T}} , rows) where {T} = StringVector (rows)
23
23
allocatecolumn (:: Type{Union{Missing, WeakRefString{T}}} , rows) where {T} = StringVector {Union{Missing, String}} (rows)
24
24
end
25
+ @require IteratorInterfaceExtensions= " 82899510-4779-5014-852e-03e436cf321d" begin
26
+ using . IteratorInterfaceExtensions
27
+ IteratorInterfaceExtensions. getiterator (x:: RowTable ) = datavaluerows (x)
28
+ IteratorInterfaceExtensions. isiterable (x:: RowTable ) = true
29
+ IteratorInterfaceExtensions. getiterator (x:: ColumnTable ) = datavaluerows (x)
30
+ IteratorInterfaceExtensions. isiterable (x:: ColumnTable ) = true
31
+ end
25
32
end
26
33
27
34
include (" utils.jl" )
@@ -89,11 +96,11 @@ struct ColumnAccess <: AccessStyle end
89
96
" Tables.schema(s) => NamedTuple{names, types}"
90
97
function schema end
91
98
92
- function istable (x :: T ) where {T}
93
- hasmethod (AccessStyle, Tuple{T}) &&
94
- hasmethod (schema, Tuple{T}) &&
95
- AccessStyle (T) === RowAccess () ? hasmethod (rows, Tuple{T}) :
96
- AccessStyle (T) === ColumnAccess () ? hasmethod (columns, Tuple{T}) : false
99
+ function istable (:: Type{T} ) where {T}
100
+ hasmethod (Tables . AccessStyle, Tuple{T}) &&
101
+ hasmethod (Tables . schema, Tuple{T}) &&
102
+ (Tables . AccessStyle (T) === Tables . RowAccess () ? hasmethod (Tables . rows, Tuple{T}) :
103
+ Tables . AccessStyle (T) === Tables . ColumnAccess () ? hasmethod (Tables . columns, Tuple{T}) : false )
97
104
end
98
105
99
106
include (" namedtuples.jl" )
@@ -154,17 +161,19 @@ end
154
161
@inline add! (val, col:: Int , nm:: Symbol , :: Base.HasLength , nt, row) = setindex! (nt[col], val, row)
155
162
@inline add! (val, col:: Int , nm:: Symbol , T, nt, row) = push! (nt[col], val)
156
163
164
+ @inline function buildcolumns (sch, rowitr:: T ) where {T}
165
+ L = Base. IteratorSize (T)
166
+ len = L == Base. HasLength () ? length (rowitr) : 0
167
+ nt = allocatecolumns (sch, len)
168
+ for (i, row) in enumerate (rowitr)
169
+ unroll (add!, sch, row, L, nt, i)
170
+ end
171
+ return nt
172
+ end
173
+
157
174
@inline function columns (x:: T ) where {T}
158
175
if AccessStyle (T) === RowAccess ()
159
- sch = schema (x)
160
- rowitr = rows (x)
161
- L = Base. IteratorSize (typeof (rowitr))
162
- len = L == Base. HasLength () ? length (rowitr) : 0
163
- nt = allocatecolumns (sch, len)
164
- for (i, row) in enumerate (rowitr)
165
- unroll (add!, sch, row, L, nt, i)
166
- end
167
- return nt
176
+ return buildcolumns (schema (x), rows (x))
168
177
elseif AccessStyle (T) === ColumnAccess ()
169
178
return x
170
179
else
0 commit comments