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/03/15 14:02:11 UTC

[GitHub] [arrow-datafusion] tustvold opened a new pull request, #5612: Miscellaneous ArrayData Cleanup

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

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


[GitHub] [arrow-datafusion] alamb merged pull request #5612: Miscellaneous ArrayData Cleanup

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


-- 
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-datafusion] tustvold commented on a diff in pull request #5612: Miscellaneous ArrayData Cleanup

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


##########
datafusion/physical-expr/src/aggregate/sum.rs:
##########
@@ -236,15 +236,15 @@ impl Accumulator for SumAccumulator {
 
     fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
         let values = &values[0];
-        self.count += (values.len() - values.data().null_count()) as u64;
+        self.count += (values.len() - values.null_count()) as u64;

Review Comment:
   This results in a test failure, as it reports the arguably correct null count, instead of 0 for NullArray. I'm not sure if this is a bug or not...



-- 
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-datafusion] Jefffrey commented on a diff in pull request #5612: Miscellaneous ArrayData Cleanup

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -627,22 +627,12 @@ impl DataFrame {
     /// # }
     /// ```
     pub async fn count(self) -> Result<usize> {
-        let rows = self
-            .aggregate(
-                vec![],
-                vec![datafusion_expr::count(Expr::Literal(ScalarValue::Null))],
-            )?
-            .collect()
-            .await?;
-        let len = *rows
-            .first()
-            .and_then(|r| r.columns().first())
-            .and_then(|c| c.as_any().downcast_ref::<Int64Array>())
-            .and_then(|a| a.values().first())
-            .ok_or(DataFusionError::Internal(
-                "Unexpected output when collecting for count()".to_string(),
-            ))? as usize;
-        Ok(len)
+        let mut stream = self.execute_stream().await?;

Review Comment:
   You could keep the old behaviour and use `datafusion_exr::utils::COUNT_STAR_EXPANSION` instead of the `ScalarValue::Null`, since `count(*)` is expanded to that in SQL planner (related bug https://github.com/apache/arrow-datafusion/pull/5518 prevents directly using `Count(Expr:Wildcard)` at the moment)
   
   The reason I had it that way was to let the count optimize out any column projections to only the minimal needed, which I think theoretically is faster than just executing the plan as is and counting the rows



-- 
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-datafusion] tustvold commented on a diff in pull request #5612: Miscellaneous ArrayData Cleanup

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -627,22 +627,12 @@ impl DataFrame {
     /// # }
     /// ```
     pub async fn count(self) -> Result<usize> {
-        let rows = self
-            .aggregate(
-                vec![],
-                vec![datafusion_expr::count(Expr::Literal(ScalarValue::Null))],
-            )?
-            .collect()
-            .await?;
-        let len = *rows
-            .first()
-            .and_then(|r| r.columns().first())
-            .and_then(|c| c.as_any().downcast_ref::<Int64Array>())
-            .and_then(|a| a.values().first())
-            .ok_or(DataFusionError::Internal(
-                "Unexpected output when collecting for count()".to_string(),
-            ))? as usize;
-        Ok(len)
+        let mut stream = self.execute_stream().await?;

Review Comment:
   I'm not sure if there is a better way to express this, in particular I'm not sure what `select count(*) from table` would compile down to, I can't help feeling there should be a better way to express this for the optimiser



-- 
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-datafusion] tustvold commented on a diff in pull request #5612: Miscellaneous ArrayData Cleanup

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -627,22 +627,12 @@ impl DataFrame {
     /// # }
     /// ```
     pub async fn count(self) -> Result<usize> {
-        let rows = self
-            .aggregate(
-                vec![],
-                vec![datafusion_expr::count(Expr::Literal(ScalarValue::Null))],

Review Comment:
   This was working by accident, as the null count for NullArray was computed incorrectly



-- 
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-datafusion] tustvold commented on a diff in pull request #5612: Miscellaneous ArrayData Cleanup

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -627,22 +627,12 @@ impl DataFrame {
     /// # }
     /// ```
     pub async fn count(self) -> Result<usize> {
-        let rows = self
-            .aggregate(
-                vec![],
-                vec![datafusion_expr::count(Expr::Literal(ScalarValue::Null))],
-            )?
-            .collect()
-            .await?;
-        let len = *rows
-            .first()
-            .and_then(|r| r.columns().first())
-            .and_then(|c| c.as_any().downcast_ref::<Int64Array>())
-            .and_then(|a| a.values().first())
-            .ok_or(DataFusionError::Internal(
-                "Unexpected output when collecting for count()".to_string(),
-            ))? as usize;
-        Ok(len)
+        let mut stream = self.execute_stream().await?;

Review Comment:
   I'm not sure if there is a better way to express this, in particular I'm not sure what `select count(*) from table` would compile down to.



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