@@ -6,3 +6,30 @@ Tables.columnaccess(::Type{<:StructVector}) = true
66Tables. columns (s:: StructVector ) = fieldarrays (s)
77
88Tables. schema (s:: StructVector ) = Tables. Schema (staticschema (eltype (s)))
9+
10+ function Base. append! (s:: StructVector , rows)
11+ if Tables. isrowtable (rows) && Tables. columnaccess (rows)
12+ # Input `rows` is a container of rows _and_ satisfies column
13+ # table interface. Thus, we can add the input column-by-column.
14+ table = Tables. columns (rows)
15+ isempty (_setdiff (propertynames (s), Tables. columnnames (rows))) ||
16+ _invalid_columns_error (s, rows)
17+ _foreach (propertynames (s)) do name
18+ append! (getproperty (s, name), Tables. getcolumn (table, name))
19+ end
20+ return s
21+ else
22+ # Otherwise, fallback to a generic implementation expecting
23+ # that `rows` is an iterator:
24+ return foldl (push!, rows; init = s)
25+ end
26+ end
27+
28+ @noinline function _invalid_columns_error (s, rows)
29+ missingnames = setdiff! (collect (Tables. columnnames (rows)), propertynames (s))
30+ throw (ArgumentError (string (
31+ " Cannot append rows from `$(typeof (rows)) ` to `$(typeof (s)) ` due to " ,
32+ " missing column(s):\n " ,
33+ join (missingnames, " , " ),
34+ )))
35+ end
0 commit comments