MCPcopy Create free account
hub / github.com/apache/arrow / Materialize

Method Materialize

r/src/altrep.cpp:189–217  ·  view source on GitHub ↗

Force materialization. After calling this, the data2 slot of the altrep object contains a standard R vector with the same data, with R sentinels where the Array has nulls. This method also releases the reference to the original ChunkedArray.

Source from the content-addressed store, hash-verified

187 // R sentinels where the Array has nulls. This method also releases the
188 // reference to the original ChunkedArray.
189 static SEXP Materialize(SEXP alt) {
190 if (!IsMaterialized(alt)) {
191 auto size = Base::Length(alt);
192
193 // create a standard R vector
194 SEXP copy = PROTECT(Rf_allocVector(sexp_type, size));
195
196 // copy the data from the array, through Get_region
197 if constexpr (std::is_same_v<c_type, double>) {
198 Get_region(alt, 0, size, REAL(copy));
199 } else if constexpr (std::is_same_v<c_type, int>) {
200 Get_region(alt, 0, size, INTEGER(copy));
201 } else {
202 static_assert(std::is_same_v<c_type, double> || std::is_same_v<c_type, int>,
203 "ALTREP not implemented for this c_type");
204 }
205
206 // store as data2, this is now considered materialized
207 SetRepresentation(alt, copy);
208
209 // we no longer need the original ChunkedArray (keeping it alive uses more
210 // memory than is required, since our methods can now use the
211 // materialized array)
212 R_set_altrep_data1(alt, R_NilValue);
213
214 UNPROTECT(1);
215 }
216 return Representation(alt);
217 }
218
219 // R calls this to get a pointer to the start of the vector data
220 // but only if this is possible without allocating (in the R sense).

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected