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

Function case_without_expr

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

Source from the content-addressed store, hash-verified

1740
1741 #[test]
1742 fn case_without_expr() -> Result<()> {
1743 let batch = case_test_batch()?;
1744 let schema = batch.schema();
1745
1746 // CASE WHEN a = 'foo' THEN 123 WHEN a = 'bar' THEN 456 END
1747 let when1 = binary(
1748 col("a", &schema)?,
1749 Operator::Eq,
1750 lit("foo"),
1751 &batch.schema(),
1752 )?;
1753 let then1 = lit(123i32);
1754 let when2 = binary(
1755 col("a", &schema)?,
1756 Operator::Eq,
1757 lit("bar"),
1758 &batch.schema(),
1759 )?;
1760 let then2 = lit(456i32);
1761
1762 let expr = generate_case_when_with_type_coercion(
1763 None,
1764 vec![(when1, then1), (when2, then2)],
1765 None,
1766 schema.as_ref(),
1767 )?;
1768 let result = expr
1769 .evaluate(&batch)?
1770 .into_array(batch.num_rows())
1771 .expect("Failed to convert to array");
1772 let result = as_int32_array(&result)?;
1773
1774 let expected = &Int32Array::from(vec![Some(123), None, None, Some(456)]);
1775
1776 assert_eq!(expected, result);
1777
1778 Ok(())
1779 }
1780
1781 #[test]
1782 fn case_with_expr_when_null() -> Result<()> {

Callers

nothing calls this directly

Calls 10

case_test_batchFunction · 0.85
binaryFunction · 0.85
as_int32_arrayFunction · 0.85
colFunction · 0.70
litFunction · 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…