MCPcopy Create free account
hub / github.com/apache/datafusion / count

Method count

datafusion/core/src/dataframe/mod.rs:1423–1440  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Calls 6

collectMethod · 0.80
columnsMethod · 0.80
aggregateMethod · 0.45
firstMethod · 0.45
as_anyMethod · 0.45
valuesMethod · 0.45

Tested by 4

df_countFunction · 0.36
unnest_columnsFunction · 0.36