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

Function test_fmt_sql

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

Source from the content-addressed store, hash-verified

2434
2435 #[test]
2436 fn test_fmt_sql() -> Result<()> {
2437 let schema = Schema::new(vec![Field::new("a", DataType::Utf8, true)]);
2438
2439 // CASE WHEN a = 'foo' THEN 123.3 ELSE 999 END
2440 let when = binary(col("a", &schema)?, Operator::Eq, lit("foo"), &schema)?;
2441 let then = lit(123.3f64);
2442 let else_value = lit(999i32);
2443
2444 let expr = generate_case_when_with_type_coercion(
2445 None,
2446 vec![(when, then)],
2447 Some(else_value),
2448 &schema,
2449 )?;
2450
2451 let display_string = expr.to_string();
2452 assert_eq!(
2453 display_string,
2454 "CASE WHEN a@0 = foo THEN 123.3 ELSE TRY_CAST(999 AS Float64) END"
2455 );
2456
2457 let sql_string = fmt_sql(expr.as_ref()).to_string();
2458 assert_eq!(
2459 sql_string,
2460 "CASE WHEN a = foo THEN 123.3 ELSE TRY_CAST(999 AS Float64) END"
2461 );
2462
2463 Ok(())
2464 }
2465
2466 fn when_then_else(
2467 when: &Arc<dyn PhysicalExpr>,

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
binaryFunction · 0.85
fmt_sqlFunction · 0.85
colFunction · 0.70
litFunction · 0.70
to_stringMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…