paleolimbot commented on code in PR #578:
URL: https://github.com/apache/arrow-nanoarrow/pull/578#discussion_r1712051964
##########
src/nanoarrow/common/array.c:
##########
@@ -1335,3 +1335,177 @@ ArrowErrorCode ArrowArrayViewValidate(struct
ArrowArrayView* array_view,
ArrowErrorSet(error, "validation_level not recognized");
return EINVAL;
}
+
+struct ArrowComparisonInternalState {
+ enum ArrowCompareLevel level;
+ int is_equal;
+ struct ArrowBuffer path;
+ struct ArrowError reason;
+};
+
+#define RETURN_NOT_EQUAL_IMPL(state_, path_size_, cond_, reason_) \
+ do { \
+ if (cond_) { \
+ ArrowErrorSet(&state_->reason, "%s", reason_); \
+ state_->path.size_bytes = (path_size_); \
+ state_->is_equal = 0; \
+ return NANOARROW_OK; \
+ } \
+ } while (0)
+
+#define RETURN_NOT_EQUAL(state_, path_size_, condition_) \
+ RETURN_NOT_EQUAL_IMPL(state_, path_size_, condition_, #condition_)
+
+static ArrowErrorCode ArrowArrayViewCompareStructure(
+ const struct ArrowArrayView* actual, const struct ArrowArrayView* expected,
+ struct ArrowComparisonInternalState* state) {
+ int64_t path_size = state->path.size_bytes;
+
+ RETURN_NOT_EQUAL(state, path_size, actual->storage_type !=
expected->storage_type);
+ RETURN_NOT_EQUAL(state, path_size, actual->n_children !=
expected->n_children);
+ RETURN_NOT_EQUAL(state, path_size,
+ actual->dictionary == NULL && expected->dictionary != NULL);
+ RETURN_NOT_EQUAL(state, path_size,
+ actual->dictionary != NULL && expected->dictionary == NULL);
+
Review Comment:
I removed the "structure" checker since it's intent wasn't clear and the
check we need to avoid invalid access on `children` or `dictionary` further
down is fairly compact.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]