Jefffrey commented on code in PR #19065:
URL: https://github.com/apache/datafusion/pull/19065#discussion_r2585163339


##########
datafusion/spark/src/function/math/width_bucket.rs:
##########
@@ -77,7 +123,16 @@ impl ScalarUDFImpl for SparkWidthBucket {
     }
 
     fn invoke_with_args(&self, args: ScalarFunctionArgs) -> 
Result<ColumnarValue> {
-        make_scalar_function(width_bucket_kern, vec![])(&args.args)
+        let [value, minv, maxv, buckets] = take_function_args(self.name(), 
&args.args)?;
+
+        let arrays = vec![
+            value.to_array(args.number_rows)?,
+            minv.to_array(args.number_rows)?,
+            maxv.to_array(args.number_rows)?,
+            buckets.to_array(args.number_rows)?,
+        ];
+
+        width_bucket_kern(&arrays).map(ColumnarValue::Array)

Review Comment:
   Was there a need for this change?



##########
datafusion/spark/src/function/math/width_bucket.rs:
##########
@@ -53,8 +59,48 @@ impl Default for SparkWidthBucket {
 
 impl SparkWidthBucket {
     pub fn new() -> Self {
+        let numeric = Coercion::new_implicit(
+            TypeSignatureClass::Native(logical_float64()),
+            vec![
+                TypeSignatureClass::Integer,
+                TypeSignatureClass::Float,
+                TypeSignatureClass::Decimal,
+            ],
+            NativeType::Float64,
+        );
+        let duration = Coercion::new_implicit(
+            TypeSignatureClass::Native(logical_duration_microsecond()),
+            vec![TypeSignatureClass::Duration],
+            NativeType::Duration(Microsecond),
+        );
+        let interval_ym = Coercion::new_exact(TypeSignatureClass::Native(
+            logical_interval_year_month(),
+        ));
+        let interval_mdn =
+            
Coercion::new_exact(TypeSignatureClass::Native(logical_interval_mdn()));
+        let bucket = Coercion::new_implicit(
+            TypeSignatureClass::Native(logical_int32()),
+            vec![TypeSignatureClass::Integer],
+            NativeType::Int32,
+        );
+        let type_signature = Signature::one_of(
+            vec![
+                width_bucket_signature(&numeric, &bucket),
+                width_bucket_signature(&duration, &bucket),
+                width_bucket_signature(&interval_ym, &bucket),
+                width_bucket_signature(&interval_mdn, &bucket),
+            ],
+            Immutable,
+        )
+        .with_parameter_names(vec![
+            "expr".to_string(),
+            "min".to_string(),
+            "max".to_string(),
+            "num_buckets".to_string(),

Review Comment:
   ```suggestion
               "expr",
               "min",
               "max",
               "num_buckets",
   ```
   
   `with_parameter_names` accepts anything `Into<String>`
   
   
https://github.com/apache/datafusion/blob/4d86ae091343b10e5ae05a2370a5b361bdfce44e/datafusion/expr-common/src/signature.rs#L1328



##########
datafusion/spark/src/function/math/width_bucket.rs:
##########
@@ -182,23 +180,25 @@ fn width_bucket_kern(args: &[ArrayRef]) -> 
Result<ArrayRef> {
             let min = as_interval_mdn_array(minv)?;
             let max = as_interval_mdn_array(maxv)?;
             let n_bucket = as_int32_array(nb)?;
-            Ok(Arc::new(width_bucket_interval_mdn_exact(v, min, max, 
n_bucket)))
+            Ok(Arc::new(width_bucket_interval_mdn_exact(
+                v, min, max, n_bucket,
+            )))
         }
 
-
-        other => Err(unsupported_data_types_exec_err(
-            "width_bucket",
-            "Float/Decimal OR Duration OR Interval(YearMonth) for first 3 
args; Int for 4th",
-            &[
-                other.clone(),
-                minv.data_type().clone(),
-                maxv.data_type().clone(),
-                nb.data_type().clone(),
-            ],
-        )),
+        other => internal_err!(
+            "width_bucket received unexpected data types: {:?}, {:?}, {:?}, 
{:?}",
+            other,
+            minv.data_type(),
+            maxv.data_type(),
+            nb.data_type()
+        ),
     }
 }
 
+fn width_bucket_signature(arg: &Coercion, bucket: &Coercion) -> TypeSignature {

Review Comment:
   I'd prefer to inline this directly



##########
datafusion/spark/src/function/math/width_bucket.rs:
##########
@@ -53,8 +59,48 @@ impl Default for SparkWidthBucket {
 
 impl SparkWidthBucket {
     pub fn new() -> Self {
+        let numeric = Coercion::new_implicit(
+            TypeSignatureClass::Native(logical_float64()),
+            vec![
+                TypeSignatureClass::Integer,
+                TypeSignatureClass::Float,
+                TypeSignatureClass::Decimal,

Review Comment:
   ```suggestion
                   TypeSignatureClass::Numeric,
   ```
   
   Numeric encompasses all three
   
   



-- 
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]

Reply via email to