| 234 | } // namespace arrow |
| 235 | |
| 236 | std::shared_ptr<arrow::RecordBatch> RecordBatch__from_arrays__known_schema( |
| 237 | const std::shared_ptr<arrow::Schema>& schema, SEXP lst) { |
| 238 | int num_fields; |
| 239 | StopIfNotOk(arrow::r::count_fields(lst, &num_fields)); |
| 240 | |
| 241 | if (schema->num_fields() != num_fields) { |
| 242 | cpp11::stop("incompatible. schema has %d fields, and %d arrays are supplied", |
| 243 | schema->num_fields(), num_fields); |
| 244 | } |
| 245 | |
| 246 | // convert lst to a vector of arrow::Array |
| 247 | std::vector<std::shared_ptr<arrow::Array>> arrays(num_fields); |
| 248 | |
| 249 | auto fill_array = [&arrays, &schema](int j, SEXP x, std::string name) { |
| 250 | if (schema->field(j)->name() != name) { |
| 251 | cpp11::stop("field at index %d has name '%s' != '%s'", j + 1, |
| 252 | schema->field(j)->name().c_str(), name.c_str()); |
| 253 | } |
| 254 | arrays[j] = arrow::r::vec_to_arrow_Array(x, schema->field(j)->type(), false); |
| 255 | }; |
| 256 | |
| 257 | arrow::r::TraverseDots(lst, num_fields, fill_array); |
| 258 | |
| 259 | int64_t num_rows = 0; |
| 260 | StopIfNotOk(arrow::r::check_consistent_array_size(arrays, &num_rows)); |
| 261 | return arrow::RecordBatch::Make(schema, num_rows, arrays); |
| 262 | } |
| 263 | |
| 264 | namespace arrow { |
| 265 | namespace r { |
no test coverage detected