Skip to content

Commit

Permalink
Add unit test: custom_scalar_overrides_duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrebnov committed Dec 27, 2024
1 parent e163f4a commit 13254d2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ mod tests {

use crate::unparser::dialect::{
CharacterLengthStyle, CustomDialect, CustomDialectBuilder, DateFieldExtractStyle,
Dialect, PostgreSqlDialect,
Dialect, DuckDBDialect, PostgreSqlDialect, ScalarFnToSqlHandler,
};

use super::*;
Expand Down Expand Up @@ -2722,4 +2722,28 @@ mod tests {

Ok(())
}

#[test]
fn test_custom_scalar_overrides_duckdb() -> Result<()> {
let duckdb_default = DuckDBDialect::new();
let duckdb_extended = DuckDBDialect::new().with_custom_scalar_overrides(vec![(
"dummy_udf",
Box::new(|unparser: &Unparser, args: &[Expr]| {
unparser.scalar_function_to_sql("smart_udf", args).map(Some)
}) as ScalarFnToSqlHandler,
)]);

for (dialect, expected) in [
(duckdb_default, r#"dummy_udf("a", "b")"#),
(duckdb_extended, r#"smart_udf("a", "b")"#),
] {
let unparser = Unparser::new(&dialect);
let expr =
ScalarUDF::new_from_impl(DummyUDF::new()).call(vec![col("a"), col("b")]);
let actual = format!("{}", unparser.expr_to_sql(&expr)?);
assert_eq!(actual, expected);
}

Ok(())
}
}

0 comments on commit 13254d2

Please sign in to comment.