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

Function garrow_table_new_values

c_glib/arrow-glib/table.cpp:289–355  ·  view source on GitHub ↗

* garrow_table_new_values: (skip) * @schema: The schema of the table. * @values: The values of the table. All values must be instance of * the same class. Available classes are #GArrowChunkedArray, * #GArrowArray and #GArrowRecordBatch. * @error: (nullable): Return location for a #GError or %NULL. * * Returns: (nullable): A newly created #GArrowTable or %NULL on error. * * Since: 0.12

Source from the content-addressed store, hash-verified

287 * Since: 0.12.0
288 */
289GArrowTable *
290garrow_table_new_values(GArrowSchema *schema, GList *values, GError **error)
291{
292 const auto context = "[table][new][values]";
293 auto arrow_schema = garrow_schema_get_raw(schema);
294 std::vector<std::shared_ptr<arrow::ChunkedArray>> arrow_chunked_arrays;
295 std::vector<std::shared_ptr<arrow::Array>> arrow_arrays;
296 std::vector<std::shared_ptr<arrow::RecordBatch>> arrow_record_batches;
297 for (GList *node = values; node; node = node->next) {
298 if (GARROW_IS_CHUNKED_ARRAY(node->data)) {
299 auto chunked_array = GARROW_CHUNKED_ARRAY(node->data);
300 arrow_chunked_arrays.push_back(garrow_chunked_array_get_raw(chunked_array));
301 } else if (GARROW_IS_ARRAY(node->data)) {
302 auto array = GARROW_ARRAY(node->data);
303 arrow_arrays.push_back(garrow_array_get_raw(array));
304 } else if (GARROW_IS_RECORD_BATCH(node->data)) {
305 auto record_batch = GARROW_RECORD_BATCH(node->data);
306 arrow_record_batches.push_back(garrow_record_batch_get_raw(record_batch));
307 } else {
308 g_set_error(error,
309 GARROW_ERROR,
310 GARROW_ERROR_INVALID,
311 "%s: %s",
312 context,
313 "value must be one of "
314 "GArrowChunkedArray, GArrowArray and GArrowRecordBatch");
315 return NULL;
316 }
317 }
318
319 size_t n_types = 0;
320 if (!arrow_chunked_arrays.empty()) {
321 ++n_types;
322 }
323 if (!arrow_arrays.empty()) {
324 ++n_types;
325 }
326 if (!arrow_record_batches.empty()) {
327 ++n_types;
328 }
329 if (n_types > 1) {
330 g_set_error(error,
331 GARROW_ERROR,
332 GARROW_ERROR_INVALID,
333 "%s: %s",
334 context,
335 "all values must be the same objects of "
336 "GArrowChunkedArray, GArrowArray or GArrowRecordBatch");
337 return NULL;
338 }
339
340 if (!arrow_chunked_arrays.empty()) {
341 auto arrow_table = arrow::Table::Make(arrow_schema, std::move(arrow_chunked_arrays));
342 return garrow_table_new_raw(&arrow_table);
343 } else if (!arrow_arrays.empty()) {
344 auto arrow_table = arrow::Table::Make(arrow_schema, std::move(arrow_arrays));
345 return garrow_table_new_raw(&arrow_table);
346 } else {

Callers

nothing calls this directly

Calls 8

garrow_schema_get_rawFunction · 0.85
push_backMethod · 0.80
garrow_array_get_rawFunction · 0.70
checkFunction · 0.70
MakeFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected