* garrow_array_cast: * @array: A #GArrowArray. * @target_data_type: A #GArrowDataType of cast target data. * @options: (nullable): A #GArrowCastOptions. * @error: (nullable): Return location for a #GError or %NULL. * * Returns: (nullable) (transfer full): * A newly created casted array on success, %NULL on error. * * Since: 0.7.0 */
| 4920 | * Since: 0.7.0 |
| 4921 | */ |
| 4922 | GArrowArray * |
| 4923 | garrow_array_cast(GArrowArray *array, |
| 4924 | GArrowDataType *target_data_type, |
| 4925 | GArrowCastOptions *options, |
| 4926 | GError **error) |
| 4927 | { |
| 4928 | auto arrow_array = garrow_array_get_raw(array); |
| 4929 | auto arrow_array_raw = arrow_array.get(); |
| 4930 | auto arrow_target_data_type = garrow_data_type_get_raw(target_data_type); |
| 4931 | arrow::Result<std::shared_ptr<arrow::Array>> arrow_casted_array; |
| 4932 | if (options) { |
| 4933 | auto arrow_options = garrow_cast_options_get_raw(options); |
| 4934 | arrow_casted_array = |
| 4935 | arrow::compute::Cast(*arrow_array_raw, arrow_target_data_type, *arrow_options); |
| 4936 | } else { |
| 4937 | arrow_casted_array = arrow::compute::Cast(*arrow_array_raw, arrow_target_data_type); |
| 4938 | } |
| 4939 | if (garrow::check(error, arrow_casted_array, [&]() { |
| 4940 | std::stringstream message; |
| 4941 | message << "[array][cast] <"; |
| 4942 | message << arrow_array->type()->ToString(); |
| 4943 | message << "> -> <"; |
| 4944 | message << arrow_target_data_type->ToString(); |
| 4945 | message << ">"; |
| 4946 | return message.str(); |
| 4947 | })) { |
| 4948 | return garrow_array_new_raw(&(*arrow_casted_array)); |
| 4949 | } else { |
| 4950 | return NULL; |
| 4951 | } |
| 4952 | } |
| 4953 | |
| 4954 | /** |
| 4955 | * garrow_array_unique: |
nothing calls this directly
no test coverage detected