You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/31 16:40:01 UTC

[GitHub] [arrow] kaoutherab commented on a change in pull request #12706: ARROW-15961: [C++] Check nullability when validating fields on batches or struct arrays

kaoutherab commented on a change in pull request #12706:
URL: https://github.com/apache/arrow/pull/12706#discussion_r839816527



##########
File path: cpp/src/arrow/array/validate.cc
##########
@@ -509,22 +510,23 @@ struct ValidateArrayImpl {
     }
 
     if (full_validation) {
-      if (data.null_count != kUnknownNullCount) {
-        int64_t actual_null_count;
-        if (HasValidityBitmap(data.type->id()) && data.buffers[0]) {
-          // Do not call GetNullCount() as it would also set the `null_count` member
-          actual_null_count = data.length - CountSetBits(data.buffers[0]->data(),
-                                                         data.offset, data.length);
-        } else if (data.type->storage_id() == Type::NA) {
-          actual_null_count = data.length;
-        } else {
-          actual_null_count = 0;
-        }
-        if (actual_null_count != data.null_count) {
-          return Status::Invalid("null_count value (", data.null_count,
-                                 ") doesn't match actual number of nulls in array (",
-                                 actual_null_count, ")");
-        }
+      int64_t actual_null_count;
+      if (HasValidityBitmap(data.type->id()) && data.buffers[0]) {
+        // Do not call GetNullCount() as it would also set the `null_count` member
+        actual_null_count =
+            data.length - CountSetBits(data.buffers[0]->data(), data.offset, data.length);
+      } else if (data.type->storage_id() == Type::NA) {
+        actual_null_count = data.length;
+      } else {
+        actual_null_count = 0;
+      }
+      if (data.null_count != kUnknownNullCount && actual_null_count != data.null_count) {
+        return Status::Invalid("null_count value (", data.null_count,
+                               ") doesn't match actual number of nulls in array (",
+                               actual_null_count, ")");
+      }
+      if (!nullable && actual_null_count > 0) {
+        return Status::Invalid("Null found but field is not nullable");
       }
     }
     return Status::OK();

Review comment:
       This is already covered in this PR (for "ValidateListLike").




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org