* 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 */
| 4875 | * Since: 0.7.0 |
| 4876 | */ |
| 4877 | GArrowArray * |
| 4878 | garrow_array_cast(GArrowArray *array, |
| 4879 | GArrowDataType *target_data_type, |
| 4880 | GArrowCastOptions *options, |
| 4881 | GError **error) |
| 4882 | { |
| 4883 | auto arrow_array = garrow_array_get_raw(array); |
| 4884 | auto arrow_array_raw = arrow_array.get(); |
| 4885 | auto arrow_target_data_type = garrow_data_type_get_raw(target_data_type); |
| 4886 | arrow::Result<std::shared_ptr<arrow::Array>> arrow_casted_array; |
| 4887 | if (options) { |
| 4888 | auto arrow_options = garrow_cast_options_get_raw(options); |
| 4889 | arrow_casted_array = |
| 4890 | arrow::compute::Cast(*arrow_array_raw, arrow_target_data_type, *arrow_options); |
| 4891 | } else { |
| 4892 | arrow_casted_array = arrow::compute::Cast(*arrow_array_raw, arrow_target_data_type); |
| 4893 | } |
| 4894 | if (garrow::check(error, arrow_casted_array, [&]() { |
| 4895 | std::stringstream message; |
| 4896 | message << "[array][cast] <"; |
| 4897 | message << arrow_array->type()->ToString(); |
| 4898 | message << "> -> <"; |
| 4899 | message << arrow_target_data_type->ToString(); |
| 4900 | message << ">"; |
| 4901 | return message.str(); |
| 4902 | })) { |
| 4903 | return garrow_array_new_raw(&(*arrow_casted_array)); |
| 4904 | } else { |
| 4905 | return NULL; |
| 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | /** |
| 4910 | * garrow_array_unique: |
nothing calls this directly
no test coverage detected