* garrow_union_array_get_field * @array: A #GArrowUnionArray. * @i: The index of the field in the union. * * Returns: (nullable) (transfer full): The i-th field values as a * #GArrowArray or %NULL on out of range. */
| 1432 | * #GArrowArray or %NULL on out of range. |
| 1433 | */ |
| 1434 | GArrowArray * |
| 1435 | garrow_union_array_get_field(GArrowUnionArray *array, gint i) |
| 1436 | { |
| 1437 | auto priv = GARROW_UNION_ARRAY_GET_PRIVATE(array); |
| 1438 | if (!priv->fields) { |
| 1439 | auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array)); |
| 1440 | auto arrow_union_array = std::static_pointer_cast<arrow::UnionArray>(arrow_array); |
| 1441 | auto n_fields = arrow_union_array->num_fields(); |
| 1442 | priv->fields = g_ptr_array_sized_new(n_fields); |
| 1443 | g_ptr_array_set_free_func(priv->fields, g_object_unref); |
| 1444 | for (int i = 0; i < n_fields; ++i) { |
| 1445 | auto arrow_field = arrow_union_array->field(i); |
| 1446 | g_ptr_array_add(priv->fields, garrow_array_new_raw(&arrow_field)); |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | if (i < 0) { |
| 1451 | i += priv->fields->len; |
| 1452 | } |
| 1453 | if (i < 0) { |
| 1454 | return NULL; |
| 1455 | } |
| 1456 | if (i >= static_cast<gint>(priv->fields->len)) { |
| 1457 | return NULL; |
| 1458 | } |
| 1459 | auto field = static_cast<GArrowArray *>(g_ptr_array_index(priv->fields, i)); |
| 1460 | g_object_ref(field); |
| 1461 | return field; |
| 1462 | } |
| 1463 | |
| 1464 | /** |
| 1465 | * garrow_union_array_get_n_fields |
nothing calls this directly
no test coverage detected