Jefffrey commented on code in PR #19788:
URL: https://github.com/apache/datafusion/pull/19788#discussion_r2689509054
##########
datafusion/functions/src/math/trunc.rs:
##########
@@ -110,6 +110,60 @@ impl ScalarUDFImpl for TruncFunc {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
+ let value = &args.args[0];
+
+ // Scalar fast path for float types with scalar or default precision
+ if let ColumnarValue::Scalar(scalar) = value {
+ // Get precision: default 0 or from second scalar arg
+ let precision = if args.args.len() >= 2 {
+ match &args.args[1] {
+ ColumnarValue::Scalar(Int64(Some(p))) => *p,
+ ColumnarValue::Scalar(Int64(None)) => {
+ // Return null with the same type as the input
+ return match scalar {
+ ScalarValue::Float32(_) => {
+
Ok(ColumnarValue::Scalar(ScalarValue::Float32(None)))
+ }
+ _ =>
Ok(ColumnarValue::Scalar(ScalarValue::Float64(None))),
+ };
+ }
+ _ => {
+ // Precision is an array - fall through to array path
+ return make_scalar_function(trunc, vec![])(&args.args);
+ }
Review Comment:
I feel there's too much nesting and return points inside here; we should try
to flatten this more, taking advantage of Rust's powerful type matching to
collapse some of these where possible
--
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]