You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/06/02 07:51:45 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #4343: Fix MutableArrayData::extend_nulls (#1230)

tustvold opened a new pull request, #4343:
URL: https://github.com/apache/arrow-rs/pull/4343

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #1230
   Closes #4324 
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   MutableArrayData::extend_nulls doesn't update the null bitmask, and so has never worked correctly. Since #3775 it most likely will result in freeze panicking. It is surprising that nobody has hit this before, although we use `MutableArrayData` in very limited places, and `MutableArrayData::extend_nulls` in even fewer.
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4343: Fix MutableArrayData::extend_nulls (#1230)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4343:
URL: https://github.com/apache/arrow-rs/pull/4343#discussion_r1214045538


##########
arrow-data/src/transform/mod.rs:
##########
@@ -53,7 +53,7 @@ struct _MutableArrayData<'a> {
     pub null_count: usize,
 
     pub len: usize,
-    pub null_buffer: MutableBuffer,
+    pub null_buffer: Option<MutableBuffer>,

Review Comment:
   This does add a branch on append, in practice appending to a null mask is so branch heavy anyway, not to mention already involving a dyn dispatch, I struggle to see how this could have an appreciable performance impact



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4343: Fix MutableArrayData::extend_nulls (#1230)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4343:
URL: https://github.com/apache/arrow-rs/pull/4343#discussion_r1214047353


##########
arrow-data/src/transform/mod.rs:
##########
@@ -624,13 +633,18 @@ impl<'a> MutableArrayData<'a> {
     }
 
     /// Extends this [MutableArrayData] with null elements, disregarding the bound arrays
+    ///
+    /// # Panics
+    ///
+    /// Panics if [`MutableArrayData`] not created with `use_nulls` or nullable source arrays
+    ///
     pub fn extend_nulls(&mut self, len: usize) {
-        // TODO: null_buffer should probably be extended here as well
-        // otherwise is_valid() could later panic
-        // add test to confirm
+        self.data.len += len;
+        let bit_len = bit_util::ceil(self.data.len, 8);
+        let nulls = self.data.null_buffer();
+        nulls.resize(bit_len, 0);
         self.data.null_count += len;
         (self.extend_nulls)(&mut self.data, len);

Review Comment:
   Despite its name this extends the **values** with nulls, it doesn't do anything to the bit mask. I'm honestly not entirely sure why the separation, but :shrug: 



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4343: Fix MutableArrayData::extend_nulls (#1230)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4343:
URL: https://github.com/apache/arrow-rs/pull/4343#discussion_r1214519196


##########
arrow-data/src/transform/mod.rs:
##########
@@ -624,13 +633,18 @@ impl<'a> MutableArrayData<'a> {
     }
 
     /// Extends this [MutableArrayData] with null elements, disregarding the bound arrays
+    ///
+    /// # Panics
+    ///
+    /// Panics if [`MutableArrayData`] not created with `use_nulls` or nullable source arrays
+    ///
     pub fn extend_nulls(&mut self, len: usize) {
-        // TODO: null_buffer should probably be extended here as well

Review Comment:
   Yup, I remember adding it at the same time as I created #1230 - I then completely forgot about it :sweat_smile: 



-- 
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


[GitHub] [arrow-rs] tustvold merged pull request #4343: Fix MutableArrayData::extend_nulls (#1230)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4343:
URL: https://github.com/apache/arrow-rs/pull/4343


-- 
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


[GitHub] [arrow-rs] alamb commented on a diff in pull request #4343: Fix MutableArrayData::extend_nulls (#1230)

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #4343:
URL: https://github.com/apache/arrow-rs/pull/4343#discussion_r1214506345


##########
arrow-data/src/transform/mod.rs:
##########
@@ -624,13 +633,18 @@ impl<'a> MutableArrayData<'a> {
     }
 
     /// Extends this [MutableArrayData] with null elements, disregarding the bound arrays
+    ///
+    /// # Panics
+    ///
+    /// Panics if [`MutableArrayData`] not created with `use_nulls` or nullable source arrays
+    ///
     pub fn extend_nulls(&mut self, len: usize) {
-        // TODO: null_buffer should probably be extended here as well

Review Comment:
   classic TODO



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4343: Fix MutableArrayData::extend_nulls (#1230)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4343:
URL: https://github.com/apache/arrow-rs/pull/4343#discussion_r1214047353


##########
arrow-data/src/transform/mod.rs:
##########
@@ -624,13 +633,18 @@ impl<'a> MutableArrayData<'a> {
     }
 
     /// Extends this [MutableArrayData] with null elements, disregarding the bound arrays
+    ///
+    /// # Panics
+    ///
+    /// Panics if [`MutableArrayData`] not created with `use_nulls` or nullable source arrays
+    ///
     pub fn extend_nulls(&mut self, len: usize) {
-        // TODO: null_buffer should probably be extended here as well
-        // otherwise is_valid() could later panic
-        // add test to confirm
+        self.data.len += len;
+        let bit_len = bit_util::ceil(self.data.len, 8);
+        let nulls = self.data.null_buffer();
+        nulls.resize(bit_len, 0);
         self.data.null_count += len;
         (self.extend_nulls)(&mut self.data, len);

Review Comment:
   Despite its name this extends the **values** with nulls, it doesn't do anything to the bit mask



##########
arrow-data/src/transform/mod.rs:
##########
@@ -624,13 +633,18 @@ impl<'a> MutableArrayData<'a> {
     }
 
     /// Extends this [MutableArrayData] with null elements, disregarding the bound arrays
+    ///
+    /// # Panics
+    ///
+    /// Panics if [`MutableArrayData`] not created with `use_nulls` or nullable source arrays
+    ///
     pub fn extend_nulls(&mut self, len: usize) {
-        // TODO: null_buffer should probably be extended here as well
-        // otherwise is_valid() could later panic
-        // add test to confirm
+        self.data.len += len;
+        let bit_len = bit_util::ceil(self.data.len, 8);
+        let nulls = self.data.null_buffer();
+        nulls.resize(bit_len, 0);
         self.data.null_count += len;
         (self.extend_nulls)(&mut self.data, len);

Review Comment:
   Despite its name this extends the **values** buffers with nulls, it doesn't do anything to the bit mask



-- 
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