You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2024/07/02 05:28:48 UTC
(arrow-adbc) branch main updated: refactor(c): Check MakeArray/Batch Error codes with macro (#1959)
This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new d9a92b81f refactor(c): Check MakeArray/Batch Error codes with macro (#1959)
d9a92b81f is described below
commit d9a92b81f0ccd723aa6a3e8b2fcbea793f2aa37e
Author: William Ayd <wi...@icloud.com>
AuthorDate: Tue Jul 2 01:28:43 2024 -0400
refactor(c): Check MakeArray/Batch Error codes with macro (#1959)
---
c/validation/adbc_validation_util.h | 49 +++++++++----------------------------
1 file changed, 12 insertions(+), 37 deletions(-)
diff --git a/c/validation/adbc_validation_util.h b/c/validation/adbc_validation_util.h
index d4f7e2d83..08401f2b4 100644
--- a/c/validation/adbc_validation_util.h
+++ b/c/validation/adbc_validation_util.h
@@ -273,54 +273,38 @@ int MakeArray(struct ArrowArray* parent, struct ArrowArray* array,
if constexpr (std::is_same<T, bool>::value || std::is_same<T, int8_t>::value ||
std::is_same<T, int16_t>::value || std::is_same<T, int32_t>::value ||
std::is_same<T, int64_t>::value) {
- if (int errno_res = ArrowArrayAppendInt(array, *v); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendInt(array, *v));
// XXX: cpplint gets weird here and thinks this is an unbraced if
} else if constexpr (std::is_same<T, // NOLINT(readability/braces)
uint8_t>::value ||
std::is_same<T, uint16_t>::value ||
std::is_same<T, uint32_t>::value ||
std::is_same<T, uint64_t>::value) {
- if (int errno_res = ArrowArrayAppendUInt(array, *v); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendUInt(array, *v));
} else if constexpr (std::is_same<T, float>::value || // NOLINT(readability/braces)
std::is_same<T, double>::value) {
- if (int errno_res = ArrowArrayAppendDouble(array, *v); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendDouble(array, *v));
} else if constexpr (std::is_same<T, std::string>::value) {
struct ArrowBufferView view;
view.data.as_char = v->c_str();
view.size_bytes = v->size();
- if (int errno_res = ArrowArrayAppendBytes(array, view); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendBytes(array, view));
} else if constexpr (std::is_same<T, std::vector<std::byte>>::value) {
static_assert(std::is_same_v<uint8_t, unsigned char>);
struct ArrowBufferView view;
view.data.as_uint8 = reinterpret_cast<const uint8_t*>(v->data());
view.size_bytes = v->size();
- if (int errno_res = ArrowArrayAppendBytes(array, view); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendBytes(array, view));
} else if constexpr (std::is_same<T, ArrowInterval*>::value) {
- if (int errno_res = ArrowArrayAppendInterval(array, *v); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendInterval(array, *v));
} else if constexpr (std::is_same<T, ArrowDecimal*>::value) {
- if (int errno_res = ArrowArrayAppendDecimal(array, *v); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendDecimal(array, *v));
} else {
static_assert(!sizeof(T), "Not yet implemented");
return ENOTSUP;
}
} else {
- if (int errno_res = ArrowArrayAppendNull(array, 1); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayAppendNull(array, 1));
}
}
return 0;
@@ -336,10 +320,7 @@ template <typename First, typename... Rest>
int MakeBatchImpl(struct ArrowArray* batch, size_t i, struct ArrowError* error,
const std::vector<std::optional<First>>& first,
const std::vector<std::optional<Rest>>&... rest) {
- if (int errno_res = MakeArray<First>(batch, batch->children[i], first);
- errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(MakeArray<First>(batch, batch->children[i], first));
return MakeBatchImpl(batch, i + 1, error, rest...);
}
@@ -347,12 +328,8 @@ int MakeBatchImpl(struct ArrowArray* batch, size_t i, struct ArrowError* error,
template <typename... T>
int MakeBatch(struct ArrowArray* batch, struct ArrowError* error,
const std::vector<std::optional<T>>&... columns) {
- if (int errno_res = ArrowArrayStartAppending(batch); errno_res != 0) {
- return errno_res;
- }
- if (int errno_res = MakeBatchImpl(batch, 0, error, columns...); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayStartAppending(batch));
+ CHECK_OK(MakeBatchImpl(batch, 0, error, columns...));
for (size_t i = 0; i < static_cast<size_t>(batch->n_children); i++) {
if (batch->length > 0 && batch->children[i]->length != batch->length) {
ADD_FAILURE() << "Column lengths are inconsistent: column " << i << " has length "
@@ -367,9 +344,7 @@ int MakeBatch(struct ArrowArray* batch, struct ArrowError* error,
template <typename... T>
int MakeBatch(struct ArrowSchema* schema, struct ArrowArray* batch,
struct ArrowError* error, const std::vector<std::optional<T>>&... columns) {
- if (int errno_res = ArrowArrayInitFromSchema(batch, schema, error); errno_res != 0) {
- return errno_res;
- }
+ CHECK_OK(ArrowArrayInitFromSchema(batch, schema, error));
return MakeBatch(batch, error, columns...);
}