Return the total number of rows in this `DataFrame`. Note that this method will actually run a plan to calculate the count, which may be slow for large or complicated DataFrames. # Example ``` # 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", CsvReadOp
(self)
| 1421 | /// # } |
| 1422 | /// ``` |
| 1423 | pub async fn count(self) -> Result<usize> { |
| 1424 | let rows = self |
| 1425 | .aggregate( |
| 1426 | vec![], |
| 1427 | vec![count(Expr::Literal(COUNT_STAR_EXPANSION, None))], |
| 1428 | )? |
| 1429 | .collect() |
| 1430 | .await?; |
| 1431 | let len = *rows |
| 1432 | .first() |
| 1433 | .and_then(|r| r.columns().first()) |
| 1434 | .and_then(|c| c.as_any().downcast_ref::<Int64Array>()) |
| 1435 | .and_then(|a| a.values().first()) |
| 1436 | .ok_or_else(|| { |
| 1437 | internal_datafusion_err!("Unexpected output when collecting for count()") |
| 1438 | })? as usize; |
| 1439 | Ok(len) |
| 1440 | } |
| 1441 | |
| 1442 | /// Execute this `DataFrame` and buffer all resulting `RecordBatch`es into memory. |
| 1443 | /// |