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

Function test_round_scalar_fn_to_expr

datafusion/sql/src/unparser/expr.rs:3232–3261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3230
3231 #[test]
3232 fn test_round_scalar_fn_to_expr() -> Result<()> {
3233 let default_dialect: Arc<dyn Dialect> = Arc::new(
3234 CustomDialectBuilder::new()
3235 .with_identifier_quote_style('"')
3236 .build(),
3237 );
3238 let postgres_dialect: Arc<dyn Dialect> = Arc::new(PostgreSqlDialect {});
3239
3240 for (dialect, identifier) in
3241 [(default_dialect, "DOUBLE"), (postgres_dialect, "NUMERIC")]
3242 {
3243 let unparser = Unparser::new(dialect.as_ref());
3244 let expr = Expr::ScalarFunction(ScalarFunction {
3245 func: Arc::new(ScalarUDF::from(
3246 datafusion_functions::math::round::RoundFunc::new(),
3247 )),
3248 args: vec![
3249 Expr::Cast(Cast::new(Box::new(col("a")), DataType::Float64)),
3250 Expr::Literal(ScalarValue::Int64(Some(2)), None),
3251 ],
3252 });
3253 let ast = unparser.expr_to_sql(&expr)?;
3254
3255 let actual = format!("{ast}");
3256 let expected = format!(r#"round(CAST("a" AS {identifier}), 2)"#);
3257
3258 assert_eq!(actual, expected);
3259 }
3260 Ok(())
3261 }
3262
3263 #[test]
3264 fn test_postgres_array_has_to_any() -> Result<()> {

Callers

nothing calls this directly

Calls 6

newFunction · 0.85
ScalarFunctionClass · 0.85
expr_to_sqlMethod · 0.80
buildMethod · 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…