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

Function case_with_expr_else

datafusion/physical-expr/src/expressions/case.rs:1675–1704  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1673
1674 #[test]
1675 fn case_with_expr_else() -> Result<()> {
1676 let batch = case_test_batch()?;
1677 let schema = batch.schema();
1678
1679 // CASE a WHEN 'foo' THEN 123 WHEN 'bar' THEN 456 ELSE 999 END
1680 let when1 = lit("foo");
1681 let then1 = lit(123i32);
1682 let when2 = lit("bar");
1683 let then2 = lit(456i32);
1684 let else_value = lit(999i32);
1685
1686 let expr = generate_case_when_with_type_coercion(
1687 Some(col("a", &schema)?),
1688 vec![(when1, then1), (when2, then2)],
1689 Some(else_value),
1690 schema.as_ref(),
1691 )?;
1692 let result = expr
1693 .evaluate(&batch)?
1694 .into_array(batch.num_rows())
1695 .expect("Failed to convert to array");
1696 let result = as_int32_array(&result)?;
1697
1698 let expected =
1699 &Int32Array::from(vec![Some(123), Some(999), Some(999), Some(456)]);
1700
1701 assert_eq!(expected, result);
1702
1703 Ok(())
1704 }
1705
1706 #[test]
1707 fn case_with_expr_divide_by_zero() -> Result<()> {

Callers

nothing calls this directly

Calls 9

case_test_batchFunction · 0.85
as_int32_arrayFunction · 0.85
litFunction · 0.70
colFunction · 0.70
schemaMethod · 0.45
as_refMethod · 0.45
into_arrayMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…