You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Veeupup (via GitHub)" <gi...@apache.org> on 2023/11/12 05:11:12 UTC

[PR] Implement func `array_pop_front` [arrow-datafusion]

Veeupup opened a new pull request, #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142

   ## 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 #6996 .
   
   ## 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 these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## 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 `api 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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "Veeupup (via GitHub)" <gi...@apache.org>.
Veeupup commented on PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#issuecomment-1807115559

   > @Veeupup Would you like to try rewriting array_pop_front / back with MutableArrayData? I think it will be much easier to understand than the current slice! and list_slice! macros.
   
   yeah, agree with you.. to understand what slice! macro does cost me some time..
   
   but this macro has been used for some other functions and for now implementation with `slice!` maybe the simplest way to do with 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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "Veeupup (via GitHub)" <gi...@apache.org>.
Veeupup commented on PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#issuecomment-1807094400

   @alamb @jayzhan211  hi! this PR is ready for review now! : )


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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "Veeupup (via GitHub)" <gi...@apache.org>.
Veeupup commented on code in PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#discussion_r1392569529


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -563,13 +563,42 @@ pub fn array_slice(args: &[ArrayRef]) -> Result<ArrayRef> {
     define_array_slice(list_array, key, extra_key, false)
 }
 
+fn general_array_pop(
+    list_array: &GenericListArray<i32>,
+    from_back: bool,
+) -> Result<(Vec<i64>, Vec<i64>)> {
+    if from_back {
+        let key = vec![0; list_array.len()];
+        let extra_key: Vec<_> = list_array
+            .iter()
+            .map(|x| x.map_or(0, |arr| arr.len() as i64 - 1))
+            .collect();
+        Ok((key, extra_key))
+    } else {
+        let key: Vec<_> = list_array.iter().map(|x| x.map_or(0, |_arr| 2)).collect();

Review Comment:
   2 is the first element position (position = index + 1) we want in the new array.
   
   We only handle two cases of the first element index: if the old array has any elements, starts from 2 (index + 1), or starts from initial.



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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#discussion_r1392906610


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -564,13 +564,30 @@ pub fn array_slice(args: &[ArrayRef]) -> Result<ArrayRef> {
     define_array_slice(list_array, key, extra_key, false)
 }
 
+fn general_array_pop(
+    list_array: &GenericListArray<i32>,
+    from_back: bool,
+) -> Result<(Vec<i64>, Vec<i64>)> {
+    if from_back {
+        let key = vec![0; list_array.len()];
+        let extra_key: Vec<_> = list_array
+            .iter()
+            .map(|x| x.map_or(0, |arr| arr.len() as i64 - 1))
+            .collect();
+        Ok((key, extra_key))
+    } else {
+        let key: Vec<_> = list_array.iter().map(|x| x.map_or(0, |_arr| 2)).collect();

Review Comment:
   ```suggestion
           let key: Vec<_> = list_array.iter().map(|x| x.map_or(0, |_| 2)).collect();
   ```



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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#issuecomment-1807110833

   @Veeupup Would you like to try rewriting array_pop_front / back with MutableArrayData? I think it will be much easier to understand than the current slice! and list_slice! macros.


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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#discussion_r1391615292


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -563,13 +563,42 @@ pub fn array_slice(args: &[ArrayRef]) -> Result<ArrayRef> {
     define_array_slice(list_array, key, extra_key, false)
 }
 
+fn general_array_pop(
+    list_array: &GenericListArray<i32>,
+    from_back: bool,
+) -> Result<(Vec<i64>, Vec<i64>)> {
+    if from_back {
+        let key = vec![0; list_array.len()];
+        let extra_key: Vec<_> = list_array
+            .iter()
+            .map(|x| x.map_or(0, |arr| arr.len() as i64 - 1))
+            .collect();
+        Ok((key, extra_key))
+    } else {
+        let key: Vec<_> = list_array.iter().map(|x| x.map_or(0, |_arr| 2)).collect();

Review Comment:
   what is 2 here? and we dont use `arr` we probably can just put `||`



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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#discussion_r1390397949


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -563,13 +563,42 @@ pub fn array_slice(args: &[ArrayRef]) -> Result<ArrayRef> {
     define_array_slice(list_array, key, extra_key, false)
 }
 
+fn general_array_pop(
+    list_array: &GenericListArray<i32>,
+    from_back: bool,
+) -> Result<(Vec<i64>, Vec<i64>)> {
+    if from_back {

Review Comment:
   nit: Since there is no common for back and front, I dont think we need to write them together, but that's fine.



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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "Veeupup (via GitHub)" <gi...@apache.org>.
Veeupup commented on PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#issuecomment-1810197721

   > Thanks @Veeupup Please more tests with nulls and empty arrays, please try to think up any possible case to prevent bug to flow in.
   > 
   > And since new built in function gets introduced we need to get this documented in `scalar_functions.md` and `expressions.md`
   
   very thanks for your advice! docs have been added!
   
   and the test for empty and NULL has already added, and you can check [empty array test](https://github.com/apache/arrow-datafusion/pull/8142/files#diff-317c67cc9ce87268e4ccec1cb75316eed82f99ae2ffc226874e5897913ffa4c8R838) and [NULL value test](https://github.com/apache/arrow-datafusion/pull/8142/files#diff-317c67cc9ce87268e4ccec1cb75316eed82f99ae2ffc226874e5897913ffa4c8R850).


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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#issuecomment-1807123963

   > > @Veeupup Would you like to try rewriting array_pop_front / back with MutableArrayData? I think it will be much easier to understand than the current slice! and list_slice! macros.
   > 
   > yeah, agree with you.. to understand what slice! macro does cost me some time..
   > 
   > but this macro has been used for some other functions and for now implementation with `slice!` maybe the simplest way to do with it?
   
   If you also spend much time on slice!, it is a good reason for us to improve on 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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#discussion_r1392905922


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -563,13 +563,42 @@ pub fn array_slice(args: &[ArrayRef]) -> Result<ArrayRef> {
     define_array_slice(list_array, key, extra_key, false)
 }
 
+fn general_array_pop(
+    list_array: &GenericListArray<i32>,
+    from_back: bool,
+) -> Result<(Vec<i64>, Vec<i64>)> {
+    if from_back {
+        let key = vec![0; list_array.len()];
+        let extra_key: Vec<_> = list_array
+            .iter()
+            .map(|x| x.map_or(0, |arr| arr.len() as i64 - 1))
+            .collect();
+        Ok((key, extra_key))
+    } else {
+        let key: Vec<_> = list_array.iter().map(|x| x.map_or(0, |_arr| 2)).collect();

Review Comment:
   thanks, please leave the comment in the code what the 2 is, so for other devs it will be easier to read the code. 
   



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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

Posted by "Veeupup (via GitHub)" <gi...@apache.org>.
Veeupup commented on code in PR #8142:
URL: https://github.com/apache/arrow-datafusion/pull/8142#discussion_r1393495905


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -563,13 +563,42 @@ pub fn array_slice(args: &[ArrayRef]) -> Result<ArrayRef> {
     define_array_slice(list_array, key, extra_key, false)
 }
 
+fn general_array_pop(
+    list_array: &GenericListArray<i32>,
+    from_back: bool,
+) -> Result<(Vec<i64>, Vec<i64>)> {
+    if from_back {
+        let key = vec![0; list_array.len()];
+        let extra_key: Vec<_> = list_array
+            .iter()
+            .map(|x| x.map_or(0, |arr| arr.len() as i64 - 1))
+            .collect();
+        Ok((key, extra_key))
+    } else {
+        let key: Vec<_> = list_array.iter().map(|x| x.map_or(0, |_arr| 2)).collect();

Review Comment:
   Fixed, thanks again! : )



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


Re: [PR] Implement func `array_pop_front` [arrow-datafusion]

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


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