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

Function ChunkedArray__from_list

r/src/chunkedarray.cpp:100–146  ·  view source on GitHub ↗

[[arrow::export]]

Source from the content-addressed store, hash-verified

98
99// [[arrow::export]]
100std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(cpp11::list chunks,
101 SEXP s_type) {
102 std::vector<std::shared_ptr<arrow::Array>> vec;
103
104 // the type might be NULL, in which case we need to infer it from the data
105 // we keep track of whether it was inferred or supplied
106 bool type_inferred = Rf_isNull(s_type);
107 R_xlen_t n = XLENGTH(chunks);
108
109 std::shared_ptr<arrow::DataType> type;
110 if (type_inferred) {
111 if (n == 0) {
112 cpp11::stop("type must be specified for empty list");
113 }
114 type = arrow::r::InferArrowType(VECTOR_ELT(chunks, 0));
115 } else {
116 type = cpp11::as_cpp<std::shared_ptr<arrow::DataType>>(s_type);
117 }
118
119 if (n == 0) {
120 std::shared_ptr<arrow::Array> array;
121 std::unique_ptr<arrow::ArrayBuilder> type_builder;
122 StopIfNotOk(arrow::MakeBuilder(gc_memory_pool(), type, &type_builder));
123 StopIfNotOk(type_builder->Finish(&array));
124 vec.push_back(array);
125 } else {
126 // the first - might differ from the rest of the loop
127 // because we might have inferred the type from the first element of the list
128 //
129 // this only really matters for dictionary arrays
130 auto chunked_array =
131 arrow::r::vec_to_arrow_ChunkedArray(chunks[0], type, type_inferred);
132 for (const auto& chunk : chunked_array->chunks()) {
133 vec.push_back(chunk);
134 }
135
136 for (R_xlen_t i = 1; i < n; i++) {
137 chunked_array = arrow::r::vec_to_arrow_ChunkedArray(chunks[i], type, false);
138 for (const auto& chunk : chunked_array->chunks()) {
139 vec.push_back(chunk);
140 }
141 }
142 }
143
144 // Use Make so we validate that chunk types are all the same
145 return ValueOrStop(arrow::ChunkedArray::Make(std::move(vec)));
146}
147
148// [[arrow::export]]
149r_vec_size ChunkedArray__ReferencedBufferSize(

Callers 1

Calls 11

stopFunction · 0.85
StopIfNotOkFunction · 0.85
gc_memory_poolFunction · 0.85
ValueOrStopFunction · 0.85
push_backMethod · 0.80
InferArrowTypeFunction · 0.70
MakeBuilderFunction · 0.50
MakeFunction · 0.50
FinishMethod · 0.45
chunksMethod · 0.45

Tested by

no test coverage detected