davidlghellin commented on code in PR #22248:
URL: https://github.com/apache/datafusion/pull/22248#discussion_r3252887245
##########
datafusion/physical-expr/src/intervals/utils.rs:
##########
@@ -193,3 +200,109 @@ fn interval_dt_to_duration_ms(dt: &IntervalDayTime) ->
Result<i64> {
)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::expressions::{Column, Literal};
+ use crate::scalar_function::ScalarFunctionExpr;
+ use arrow::datatypes::{Field, Schema};
+ use datafusion_common::ScalarValue;
+ use datafusion_common::config::ConfigOptions;
+
+ fn f64_schema() -> SchemaRef {
+ Arc::new(Schema::new(vec![Field::new("x", DataType::Float64, false)]))
+ }
+
+ fn utf8_schema() -> SchemaRef {
+ Arc::new(Schema::new(vec![Field::new("s", DataType::Utf8, false)]))
+ }
+
+ fn col_x() -> Arc<dyn PhysicalExpr> {
+ Arc::new(Column::new("x", 0))
+ }
+
+ fn lit_f64(v: f64) -> Arc<dyn PhysicalExpr> {
+ Arc::new(Literal::new(ScalarValue::Float64(Some(v))))
+ }
+
+ fn scalar_fn_expr(
+ udf: Arc<datafusion_expr::ScalarUDF>,
+ args: Vec<Arc<dyn PhysicalExpr>>,
+ return_type: DataType,
+ ) -> Arc<dyn PhysicalExpr> {
+ let name = udf.name().to_string();
+ Arc::new(ScalarFunctionExpr::new(
+ &name,
+ udf,
+ args,
+ Field::new("result", return_type, true).into(),
+ Arc::new(ConfigOptions::default()),
+ ))
+ }
+
+ #[test]
+ fn test_check_support_scalar_fn_supported_return_type() {
+ // ceil(x) returns Float64 — both return type and child are supported
+ let schema = f64_schema();
+ let expr = scalar_fn_expr(
+ datafusion_functions::math::ceil(),
+ vec![col_x()],
+ DataType::Float64,
+ );
+ assert!(check_support(&expr, &schema));
+ }
+
+ #[test]
+ fn test_check_support_scalar_fn_unsupported_return_type() {
+ // A UDF that returns Utf8 — not in is_datatype_supported
+ let schema = f64_schema();
+ let expr = scalar_fn_expr(
+ datafusion_functions::math::ceil(),
+ vec![col_x()],
+ DataType::Utf8,
+ );
+ assert!(!check_support(&expr, &schema));
+ }
Review Comment:
Fixed in the latest push — replaced with a dedicated Utf8UDF test helper
that legitimately declares Utf8 as its return type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]