Skip to content

Commit cd322e4

Browse files
authored
fix: ffi aggregation (#15576)
* fix ffi * skip format * clippy
1 parent a7e71a7 commit cd322e4

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

datafusion/ffi/src/table_provider.rs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,10 @@ unsafe extern "C" fn scan_fn_wrapper(
259259
};
260260

261261
let projections: Vec<_> = projections.into_iter().collect();
262-
let maybe_projections = match projections.is_empty() {
263-
true => None,
264-
false => Some(&projections),
265-
};
266262

267263
let plan = rresult_return!(
268264
internal_provider
269-
.scan(&ctx.state(), maybe_projections, &filters, limit.into())
265+
.scan(&ctx.state(), Some(&projections), &filters, limit.into())
270266
.await
271267
);
272268

@@ -600,4 +596,49 @@ mod tests {
600596

601597
Ok(())
602598
}
599+
600+
#[tokio::test]
601+
async fn test_aggregation() -> Result<()> {
602+
use arrow::datatypes::Field;
603+
use datafusion::arrow::{
604+
array::Float32Array, datatypes::DataType, record_batch::RecordBatch,
605+
};
606+
use datafusion::common::assert_batches_eq;
607+
use datafusion::datasource::MemTable;
608+
609+
let schema =
610+
Arc::new(Schema::new(vec![Field::new("a", DataType::Float32, false)]));
611+
612+
// define data in two partitions
613+
let batch1 = RecordBatch::try_new(
614+
Arc::clone(&schema),
615+
vec![Arc::new(Float32Array::from(vec![2.0, 4.0, 8.0]))],
616+
)?;
617+
618+
let ctx = SessionContext::new();
619+
620+
let provider = Arc::new(MemTable::try_new(schema, vec![vec![batch1]])?);
621+
622+
let ffi_provider = FFI_TableProvider::new(provider, true, None);
623+
624+
let foreign_table_provider: ForeignTableProvider = (&ffi_provider).into();
625+
626+
ctx.register_table("t", Arc::new(foreign_table_provider))?;
627+
628+
let result = ctx
629+
.sql("SELECT COUNT(*) as cnt FROM t")
630+
.await?
631+
.collect()
632+
.await?;
633+
#[rustfmt::skip]
634+
let expected = [
635+
"+-----+",
636+
"| cnt |",
637+
"+-----+",
638+
"| 3 |",
639+
"+-----+"
640+
];
641+
assert_batches_eq!(expected, &result);
642+
Ok(())
643+
}
603644
}

0 commit comments

Comments
 (0)