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/14 11:09:06 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #4415: Add DictionaryArray::occupancy

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

   # 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.
   -->
   
   Part of #4414 
   Relates to https://github.com/apache/arrow-rs/issues/506
   
   
   # 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.
   -->
   
   Split out from #3558 this adds a `DictionaryArray::occupancy` which provides a mask of the "used" values. This is effectively a selection vector for the values (#4095)
   
   # 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 merged pull request #4415: Add DictionaryArray::occupancy

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


-- 
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 #4415: Add DictionaryArray::occupancy

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


##########
arrow-array/src/array/dictionary_array.rs:
##########
@@ -549,6 +550,29 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {
             .for_each(|v| *v = op(*v));
         Ok(builder.finish())
     }
+
+    /// Computes an occupancy mask for this dictionary's values
+    ///
+    /// For each value in [`Self::values`] the corresponding bit will be set in the
+    /// returned mask if it is referenced by a key in this [`DictionaryArray`]
+    pub fn occupancy(&self) -> BooleanBuffer {
+        let len = self.values.len();
+        let mut builder = BooleanBufferBuilder::new(len);
+        builder.resize(len);
+        let slice = builder.as_slice_mut();
+        match self.keys.nulls().filter(|n| n.null_count() > 0) {

Review Comment:
   This is a fancy way to check for nulls -- TIL `Option::filter` 👍 



##########
arrow-array/src/array/dictionary_array.rs:
##########
@@ -549,6 +550,29 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {
             .for_each(|v| *v = op(*v));
         Ok(builder.finish())
     }
+
+    /// Computes an occupancy mask for this dictionary's values
+    ///
+    /// For each value in [`Self::values`] the corresponding bit will be set in the
+    /// returned mask if it is referenced by a key in this [`DictionaryArray`]
+    pub fn occupancy(&self) -> BooleanBuffer {
+        let len = self.values.len();
+        let mut builder = BooleanBufferBuilder::new(len);
+        builder.resize(len);
+        let slice = builder.as_slice_mut();
+        match self.keys.nulls().filter(|n| n.null_count() > 0) {
+            Some(n) => {
+                let v = self.keys.values();
+                n.valid_indices()
+                    .for_each(|idx| set_bit(slice, v[idx].as_usize()))

Review Comment:
   Would there be any value in calling `valid_slices` here instead? I assume it would be a tradeoff for sparse dictionaries and mostly used dictionaries. 



##########
arrow-array/src/array/dictionary_array.rs:
##########
@@ -549,6 +550,29 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {
             .for_each(|v| *v = op(*v));
         Ok(builder.finish())
     }
+
+    /// Computes an occupancy mask for this dictionary's values
+    ///
+    /// For each value in [`Self::values`] the corresponding bit will be set in the
+    /// returned mask if it is referenced by a key in this [`DictionaryArray`]
+    pub fn occupancy(&self) -> BooleanBuffer {
+        let len = self.values.len();
+        let mut builder = BooleanBufferBuilder::new(len);
+        builder.resize(len);
+        let slice = builder.as_slice_mut();

Review Comment:
   nit: calling this `target` or `dest` or `dst` I think would be a more descriptive name for what it is rather than `slice`



-- 
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 pull request #4415: Add DictionaryArray::occupancy

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

   is this PR waiting on anything else? Or shall we merge it?


-- 
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 pull request #4415: Add DictionaryArray::occupancy

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

   As an aside, I really like how the new ScalarBuffer / NullBuffer structures are so easy to work with ❤️ 


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