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

Function case_with_expr

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

Source from the content-addressed store, hash-verified

1485
1486 #[test]
1487 fn case_with_expr() -> Result<()> {
1488 let batch = case_test_batch()?;
1489 let schema = batch.schema();
1490
1491 // CASE a WHEN 'foo' THEN 123 WHEN 'bar' THEN 456 END
1492 let when1 = lit("foo");
1493 let then1 = lit(123i32);
1494 let when2 = lit("bar");
1495 let then2 = lit(456i32);
1496
1497 let expr = generate_case_when_with_type_coercion(
1498 Some(col("a", &schema)?),
1499 vec![(when1, then1), (when2, then2)],
1500 None,
1501 schema.as_ref(),
1502 )?;
1503 let result = expr
1504 .evaluate(&batch)?
1505 .into_array(batch.num_rows())
1506 .expect("Failed to convert to array");
1507 let result = as_int32_array(&result)?;
1508
1509 let expected = &Int32Array::from(vec![Some(123), None, None, Some(456)]);
1510
1511 assert_eq!(expected, result);
1512
1513 Ok(())
1514 }
1515
1516 #[test]
1517 fn case_with_expr_dictionary() -> 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…