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

Function test_first_group_acc

datafusion/functions-aggregate/src/first_last.rs:1531–1622  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1529
1530 #[test]
1531 fn test_first_group_acc() -> Result<()> {
1532 let schema = Arc::new(Schema::new(vec![
1533 Field::new("a", DataType::Int64, true),
1534 Field::new("b", DataType::Int64, true),
1535 Field::new("c", DataType::Int64, true),
1536 Field::new("d", DataType::Int32, true),
1537 Field::new("e", DataType::Boolean, true),
1538 ]));
1539
1540 let sort_keys = [PhysicalSortExpr {
1541 expr: col("c", &schema).unwrap(),
1542 options: SortOptions::default(),
1543 }];
1544
1545 let mut group_acc = FirstLastGroupsAccumulator::try_new(
1546 PrimitiveValueState::<Int64Type>::new(DataType::Int64),
1547 sort_keys.into(),
1548 true,
1549 &[DataType::Int64],
1550 true,
1551 )?;
1552
1553 let mut val_with_orderings = {
1554 let mut val_with_orderings = Vec::<ArrayRef>::new();
1555
1556 let vals = Arc::new(Int64Array::from(vec![Some(1), None, Some(3), Some(-6)]));
1557 let orderings = Arc::new(Int64Array::from(vec![1, -9, 3, -6]));
1558
1559 val_with_orderings.push(vals);
1560 val_with_orderings.push(orderings);
1561
1562 val_with_orderings
1563 };
1564
1565 group_acc.update_batch(
1566 &val_with_orderings,
1567 &[0, 1, 2, 1],
1568 Some(&BooleanArray::from(vec![true, true, false, true])),
1569 3,
1570 )?;
1571 assert_eq!(
1572 group_acc.size_of_orderings,
1573 group_acc.compute_size_of_orderings()
1574 );
1575
1576 let state = group_acc.state(EmitTo::All)?;
1577
1578 let expected_state: Vec<Arc<dyn Array>> = vec![
1579 Arc::new(Int64Array::from(vec![Some(1), Some(-6), None])),
1580 Arc::new(Int64Array::from(vec![Some(1), Some(-6), None])),
1581 Arc::new(BooleanArray::from(vec![true, true, false])),
1582 ];
1583 assert_eq!(state, expected_state);
1584
1585 assert_eq!(
1586 group_acc.size_of_orderings,
1587 group_acc.compute_size_of_orderings()
1588 );

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
colFunction · 0.50
intoMethod · 0.45
pushMethod · 0.45
update_batchMethod · 0.45
stateMethod · 0.45
merge_batchMethod · 0.45
clearMethod · 0.45
evaluateMethod · 0.45
as_anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…