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/07/12 17:32:10 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #4511: Cleanup cast_primitive_to_list

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

   # 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 #.
   
   # 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.
   -->
   
   # 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 #4511: Cleanup cast_primitive_to_list

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


##########
arrow-cast/src/cast.rs:
##########
@@ -9448,4 +9420,21 @@ mod tests {
         assert_eq!("1969-12-31", string_array.value(1));
         assert_eq!("1989-12-31", string_array.value(2));
     }
+
+    #[test]
+    fn test_nested_list() {

Review Comment:
   This is not new functionality, I just couldn't find a test of 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] tustvold commented on a diff in pull request #4511: Cleanup cast_primitive_to_list

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3645,39 +3641,15 @@ where
 }
 
 /// Helper function that takes a primitive array and casts to a (generic) list array.
-fn cast_primitive_to_list<OffsetSize: OffsetSizeTrait + NumCast>(
+fn cast_values_to_list<O: OffsetSizeTrait>(
     array: &dyn Array,
-    to: &Field,
-    to_type: &DataType,
+    to: &FieldRef,
     cast_options: &CastOptions,
 ) -> Result<ArrayRef, ArrowError> {
-    // cast primitive to list's primitive
-    let cast_array = cast_with_options(array, to.data_type(), cast_options)?;
-    // create offsets, where if array.len() = 2, we have [0,1,2]
-    // Safety:
-    // Length of range can be trusted.
-    // Note: could not yet create a generic range in stable Rust.
-    let offsets = unsafe {
-        MutableBuffer::from_trusted_len_iter(
-            (0..=array.len()).map(|i| OffsetSize::from(i).expect("integer")),
-        )
-    };
-
-    let list_data = unsafe {
-        ArrayData::new_unchecked(
-            to_type.clone(),
-            array.len(),
-            Some(cast_array.null_count()),
-            cast_array.nulls().map(|b| b.inner().sliced()),

Review Comment:
   There is no reason to duplicate the null buffer here, so I opted to just remove this. I can easily revert if people feel it is better to include the child null mask twice



-- 
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 #4511: Cleanup cast_primitive_to_list

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


##########
arrow-cast/src/cast.rs:
##########
@@ -5098,7 +5070,7 @@ mod tests {
         )
         .unwrap();
         assert_eq!(5, b.len());
-        assert_eq!(1, b.null_count());
+        assert_eq!(0, b.null_count());

Review Comment:
   Is the difference that b[1] is [null] (aka a 1 element list with a null) rather than null itself? I believe that is already covered below.



##########
arrow-cast/src/cast.rs:
##########
@@ -9448,4 +9420,21 @@ mod tests {
         assert_eq!("1969-12-31", string_array.value(1));
         assert_eq!("1989-12-31", string_array.value(2));
     }
+
+    #[test]
+    fn test_nested_list() {
+        let mut list = ListBuilder::new(Int32Builder::new());
+        list.append_value([Some(1), Some(2), Some(3)]);
+        list.append_value([Some(4), Some(5), Some(6)]);

Review Comment:
   Can we please include a NULL in the list -- for example, 
   
   ```suggestion
           list.append_value([Some(4), Null, Some(6)]);
   ```



-- 
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 #4511: Cleanup cast_primitive_to_list

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


-- 
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 #4511: Cleanup cast_primitive_to_list

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


##########
arrow-cast/src/cast.rs:
##########
@@ -3645,39 +3641,15 @@ where
 }
 
 /// Helper function that takes a primitive array and casts to a (generic) list array.
-fn cast_primitive_to_list<OffsetSize: OffsetSizeTrait + NumCast>(
+fn cast_values_to_list<O: OffsetSizeTrait>(
     array: &dyn Array,
-    to: &Field,
-    to_type: &DataType,
+    to: &FieldRef,
     cast_options: &CastOptions,
 ) -> Result<ArrayRef, ArrowError> {
-    // cast primitive to list's primitive
-    let cast_array = cast_with_options(array, to.data_type(), cast_options)?;
-    // create offsets, where if array.len() = 2, we have [0,1,2]
-    // Safety:
-    // Length of range can be trusted.
-    // Note: could not yet create a generic range in stable Rust.
-    let offsets = unsafe {
-        MutableBuffer::from_trusted_len_iter(
-            (0..=array.len()).map(|i| OffsetSize::from(i).expect("integer")),
-        )
-    };
-
-    let list_data = unsafe {
-        ArrayData::new_unchecked(
-            to_type.clone(),
-            array.len(),
-            Some(cast_array.null_count()),
-            cast_array.nulls().map(|b| b.inner().sliced()),

Review Comment:
   There is no reason to duplicate the null buffer here, so I opted to just remove this



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