Skip to content

Commit

Permalink
ARROW-8347: [C++] Migrate Array methods to Result<T>
Browse files Browse the repository at this point in the history
Closes #6851 from pitrou/ARROW-8347-array-result-apis

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
pitrou committed Apr 7, 2020
1 parent 0bc3517 commit cda6a4b
Show file tree
Hide file tree
Showing 43 changed files with 654 additions and 611 deletions.
7 changes: 3 additions & 4 deletions c_glib/arrow-glib/basic-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,9 @@ garrow_array_view(GArrowArray *array,
{
auto arrow_array_raw = garrow_array_get_raw(array);
auto arrow_return_type = garrow_data_type_get_raw(return_type);
std::shared_ptr<arrow::Array> arrow_array;
auto status = arrow_array_raw->View(arrow_return_type, &arrow_array);
if (garrow_error_check(error, status, "[array][view]")) {
return garrow_array_new_raw(&arrow_array);
auto arrow_array = arrow_array_raw->View(arrow_return_type);
if (garrow::check(error, arrow_array, "[array][view]")) {
return garrow_array_new_raw(&(*arrow_array));
} else {
return NULL;
}
Expand Down
83 changes: 32 additions & 51 deletions c_glib/arrow-glib/composite-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,13 @@ garrow_struct_array_flatten(GArrowStructArray *array, GError **error)
std::static_pointer_cast<arrow::StructArray>(arrow_array);

auto memory_pool = arrow::default_memory_pool();
arrow::ArrayVector arrow_arrays;
auto status = arrow_struct_array->Flatten(memory_pool, &arrow_arrays);
if (!garrow_error_check(error, status, "[struct-array][flatten]")) {
auto arrow_arrays = arrow_struct_array->Flatten(memory_pool);
if (!garrow::check(error, arrow_arrays, "[struct-array][flatten]")) {
return NULL;
}

GList *arrays = NULL;
for (auto arrow_array : arrow_arrays) {
for (auto arrow_array : *arrow_arrays) {
auto array = garrow_array_new_raw(&arrow_array);
arrays = g_list_prepend(arrays, array);
}
Expand Down Expand Up @@ -411,15 +410,13 @@ garrow_map_array_new(GArrowArray *offsets,
const auto arrow_offsets = garrow_array_get_raw(offsets);
const auto arrow_keys = garrow_array_get_raw(keys);
const auto arrow_items = garrow_array_get_raw(items);
std::shared_ptr<arrow::Array> arrow_array;
auto arrow_memory_pool = arrow::default_memory_pool();
auto status = arrow::MapArray::FromArrays(arrow_offsets,
arrow_keys,
arrow_items,
arrow_memory_pool,
&arrow_array);
if (garrow::check(error, status, "[map-array][new]")) {
return GARROW_MAP_ARRAY(garrow_array_new_raw(&arrow_array));
auto arrow_array = arrow::MapArray::FromArrays(arrow_offsets,
arrow_keys,
arrow_items,
arrow_memory_pool);
if (garrow::check(error, arrow_array, "[map-array][new]")) {
return GARROW_MAP_ARRAY(garrow_array_new_raw(&(*arrow_array)));
} else {
return NULL;
}
Expand Down Expand Up @@ -543,12 +540,10 @@ garrow_sparse_union_array_new(GArrowInt8Array *type_ids,
auto *field = GARROW_ARRAY(node->data);
arrow_fields.push_back(garrow_array_get_raw(field));
}
std::shared_ptr<arrow::Array> arrow_union_array;
auto status = arrow::UnionArray::MakeSparse(*arrow_type_ids,
arrow_fields,
&arrow_union_array);
if (garrow_error_check(error, status, "[sparse-union-array][new]")) {
return GARROW_SPARSE_UNION_ARRAY(garrow_array_new_raw(&arrow_union_array));
auto arrow_union_array = arrow::UnionArray::MakeSparse(*arrow_type_ids,
arrow_fields);
if (garrow::check(error, arrow_union_array, "[sparse-union-array][new]")) {
return GARROW_SPARSE_UNION_ARRAY(garrow_array_new_raw(&(*arrow_union_array)));
} else {
return NULL;
}
Expand Down Expand Up @@ -586,16 +581,11 @@ garrow_sparse_union_array_new_data_type(GArrowSparseUnionDataType *data_type,
auto *field = GARROW_ARRAY(node->data);
arrow_fields.push_back(garrow_array_get_raw(field));
}
std::shared_ptr<arrow::Array> arrow_union_array;
auto status = arrow::UnionArray::MakeSparse(*arrow_type_ids,
arrow_fields,
arrow_field_names,
arrow_union_data_type->type_codes(),
&arrow_union_array);
if (garrow_error_check(error,
status,
"[sparse-union-array][new][data-type]")) {
return GARROW_SPARSE_UNION_ARRAY(garrow_array_new_raw(&arrow_union_array));
auto arrow_union_array = arrow::UnionArray::MakeSparse(
*arrow_type_ids, arrow_fields, arrow_field_names,
arrow_union_data_type->type_codes());
if (garrow::check(error, arrow_union_array, "[sparse-union-array][new][data-type]")) {
return GARROW_SPARSE_UNION_ARRAY(garrow_array_new_raw(&(*arrow_union_array)));
} else {
return NULL;
}
Expand Down Expand Up @@ -643,13 +633,11 @@ garrow_dense_union_array_new(GArrowInt8Array *type_ids,
auto *field = GARROW_ARRAY(node->data);
arrow_fields.push_back(garrow_array_get_raw(field));
}
std::shared_ptr<arrow::Array> arrow_union_array;
auto status = arrow::UnionArray::MakeDense(*arrow_type_ids,
*arrow_value_offsets,
arrow_fields,
&arrow_union_array);
if (garrow_error_check(error, status, "[dense-union-array][new]")) {
return GARROW_DENSE_UNION_ARRAY(garrow_array_new_raw(&arrow_union_array));
auto arrow_union_array = arrow::UnionArray::MakeDense(*arrow_type_ids,
*arrow_value_offsets,
arrow_fields);
if (garrow::check(error, arrow_union_array, "[dense-union-array][new]")) {
return GARROW_DENSE_UNION_ARRAY(garrow_array_new_raw(&(*arrow_union_array)));
} else {
return NULL;
}
Expand Down Expand Up @@ -691,15 +679,11 @@ garrow_dense_union_array_new_data_type(GArrowDenseUnionDataType *data_type,
auto *field = GARROW_ARRAY(node->data);
arrow_fields.push_back(garrow_array_get_raw(field));
}
std::shared_ptr<arrow::Array> arrow_union_array;
auto status = arrow::UnionArray::MakeDense(*arrow_type_ids,
*arrow_value_offsets,
arrow_fields,
arrow_field_names,
arrow_union_data_type->type_codes(),
&arrow_union_array);
if (garrow_error_check(error, status, "[dense-union-array][new][data-type]")) {
return GARROW_DENSE_UNION_ARRAY(garrow_array_new_raw(&arrow_union_array));
auto arrow_union_array = arrow::UnionArray::MakeDense(
*arrow_type_ids, *arrow_value_offsets, arrow_fields, arrow_field_names,
arrow_union_data_type->type_codes());
if (garrow::check(error, arrow_union_array, "[dense-union-array][new][data-type]")) {
return GARROW_DENSE_UNION_ARRAY(garrow_array_new_raw(&(*arrow_union_array)));
} else {
return NULL;
}
Expand Down Expand Up @@ -741,14 +725,11 @@ garrow_dictionary_array_new(GArrowDataType *data_type,
const auto arrow_data_type = garrow_data_type_get_raw(data_type);
const auto arrow_indices = garrow_array_get_raw(indices);
const auto arrow_dictionary = garrow_array_get_raw(dictionary);
std::shared_ptr<arrow::Array> arrow_dictionary_array;
auto status = arrow::DictionaryArray::FromArrays(arrow_data_type,
arrow_indices,
arrow_dictionary,
&arrow_dictionary_array);
if (garrow_error_check(error, status, "[dictionary-array][new]")) {
auto arrow_dictionary_array = arrow::DictionaryArray::FromArrays(
arrow_data_type, arrow_indices, arrow_dictionary);
if (garrow::check(error, arrow_dictionary_array, "[dictionary-array][new]")) {
auto arrow_array =
std::static_pointer_cast<arrow::Array>(arrow_dictionary_array);
std::static_pointer_cast<arrow::Array>(*arrow_dictionary_array);
return GARROW_DICTIONARY_ARRAY(garrow_array_new_raw(&arrow_array));
} else {
return NULL;
Expand Down
Loading

0 comments on commit cda6a4b

Please sign in to comment.