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

[GitHub] [arrow-datafusion] Jefffrey opened a new pull request, #5071: DataFrame len method

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

   # 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 #1926.
   
   # 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.
   -->
   
   New `len()` method on DataFrame
   
   # 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)?
   -->
   
   New unit test
   
   # 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] ursabot commented on pull request #5071: DataFrame count method

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

   Benchmark runs are scheduled for baseline = 7d2318b359f07f7734b6090f0c5defa3bfa63055 and contender = a780a0bc1d0296f30582ce97f19a6d3a8bcc6725. a780a0bc1d0296f30582ce97f19a6d3a8bcc6725 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/740781c89cc342b4ada03c2f988b23cb...cebddffdbd8440bf94e706d2ed2e2218/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ad9a305fb8a04a489b791ebfb783f598...2882f9527b844f2fa733ee59ca10ab9f/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/34c47ba5d5d94f1eb1c440f17e522415...a9dce92e9123425faec02d9e81214d62/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/c6fc4075a89b482aa55a620ccad5df42...98b2ed1846004a95ad47770c21a2af58/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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 #5071: DataFrame count method

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -361,6 +363,39 @@ impl DataFrame {
         Ok(DataFrame::new(self.session_state, plan))
     }
 
+    /// Run a count aggregate on the DataFrame and execute the DataFrame to collect this
+    /// count and return it as a usize, to find the total number of rows after executing
+    /// the DataFrame.
+    /// ```
+    /// # use datafusion::prelude::*;
+    /// # use datafusion::error::Result;
+    /// # #[tokio::main]
+    /// # async fn main() -> Result<()> {
+    /// let ctx = SessionContext::new();
+    /// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
+    /// let count = df.count().await?;
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub async fn count(self) -> Result<usize> {
+        let rows = self
+            .aggregate(
+                vec![],
+                vec![datafusion_expr::count(Expr::Literal(ScalarValue::Null))],

Review Comment:
   This was actually working by accident as a result of a quirk of NullArray whereby it doesn't have a null buffer despite all values being null. The count reported by this query should be 0 as only non-null values are counted.
   
   Fix in https://github.com/apache/arrow-datafusion/pull/5612/files#diff-932cfd7271917561280a69edabb35cfd109d22ae736f77e85adcf63455918121R630



-- 
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] viirya commented on a diff in pull request #5071: DataFrame len method

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -361,6 +364,35 @@ impl DataFrame {
         Ok(DataFrame::new(self.session_state, plan))
     }
 
+    /// Run a count aggregate on the DataFrame and execute the DataFrame to collect this
+    /// count and return it as a usize.
+    /// ```
+    /// # use datafusion::prelude::*;
+    /// # use datafusion::error::Result;
+    /// # #[tokio::main]
+    /// # async fn main() -> Result<()> {
+    /// let ctx = SessionContext::new();
+    /// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
+    /// let length = df.len().await?;
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub async fn len(self) -> Result<usize> {

Review Comment:
   Hmm, could it be `count`? For DataFrame-like API, there is commonly `count` for 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


[GitHub] [arrow-datafusion] andygrove commented on pull request #5071: DataFrame count method

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

   clippy failures can be fixed by merging latest from master


-- 
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] andygrove merged pull request #5071: DataFrame count method

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


-- 
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] viirya commented on a diff in pull request #5071: DataFrame len method

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -361,6 +364,35 @@ impl DataFrame {
         Ok(DataFrame::new(self.session_state, plan))
     }
 
+    /// Run a count aggregate on the DataFrame and execute the DataFrame to collect this
+    /// count and return it as a usize.
+    /// ```
+    /// # use datafusion::prelude::*;
+    /// # use datafusion::error::Result;
+    /// # #[tokio::main]
+    /// # async fn main() -> Result<()> {
+    /// let ctx = SessionContext::new();
+    /// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
+    /// let length = df.len().await?;
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub async fn len(self) -> Result<usize> {

Review Comment:
   Hmm, could it be `count`? For DataFrame-like API (pandas, Spark, etc.), there is commonly `count` for 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


[GitHub] [arrow-datafusion] Jefffrey commented on a diff in pull request #5071: DataFrame len method

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


##########
datafusion/core/src/dataframe.rs:
##########
@@ -361,6 +364,35 @@ impl DataFrame {
         Ok(DataFrame::new(self.session_state, plan))
     }
 
+    /// Run a count aggregate on the DataFrame and execute the DataFrame to collect this
+    /// count and return it as a usize.
+    /// ```
+    /// # use datafusion::prelude::*;
+    /// # use datafusion::error::Result;
+    /// # #[tokio::main]
+    /// # async fn main() -> Result<()> {
+    /// let ctx = SessionContext::new();
+    /// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
+    /// let length = df.len().await?;
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub async fn len(self) -> Result<usize> {

Review Comment:
   yeah that makes sense, changed



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