jiangzhx commented on issue #5444:
URL:
https://github.com/apache/arrow-datafusion/issues/5444#issuecomment-1451841791
The following code can resolve my problem.
but anyone can give some good suggestion to make code look nice.
```
#[tokio::test]
async fn count_df() -> Result<()> {
let ctx = SessionContext::new();
let testdata = datafusion::test_util::parquet_test_data();
let filename = &format!("{testdata}/alltypes_tiny_pages.parquet");
let df = ctx
.read_parquet(filename, ParquetReadOptions::default())
.await?;
let cnt = df
.clone()
.aggregate(
vec![],
vec![
datafusion_expr::count(col("id")),
datafusion_expr::count(col("bool_col")),
],
)
.unwrap();
let cnt = cnt
.clone()
.select(
cnt.schema()
.fields()
.iter()
.zip(df.schema().fields())
.map(|(count_field, orgin_field)| {
col(count_field.name()).alias(orgin_field.name())
})
.collect::<Vec<_>>(),
)
.unwrap();
let physical_plan = ctx
.state()
.create_physical_plan(&cnt.logical_plan())
.await
.unwrap();
println!("{}", displayable(physical_plan.as_ref()).indent());
let batch = collect(physical_plan, ctx.task_ctx()).await.unwrap();
print_batches(&*batch);
Ok(())
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]