kosiew commented on code in PR #1287:
URL: 
https://github.com/apache/datafusion-python/pull/1287#discussion_r2454625018


##########
src/udf.rs:
##########
@@ -80,6 +81,83 @@ fn to_scalar_function_impl(func: PyObject) -> 
ScalarFunctionImplementation {
     })
 }
 
+#[derive(PartialEq, Eq, Hash)]
+struct PySimpleScalarUDF {
+    name: String,
+    signature: Signature,
+    return_field: Arc<Field>,
+    fun: PtrEq<ScalarFunctionImplementation>,
+}
+
+impl fmt::Debug for PySimpleScalarUDF {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_struct("PySimpleScalarUDF")
+            .field("name", &self.name)
+            .field("signature", &self.signature)
+            .field("return_field", &self.return_field)
+            .finish()
+    }
+}
+
+impl PySimpleScalarUDF {
+    fn new(
+        name: impl Into<String>,
+        input_fields: Vec<Field>,
+        return_field: Field,
+        volatility: Volatility,
+        fun: ScalarFunctionImplementation,
+    ) -> Self {
+        let signature_types = input_fields
+            .into_iter()
+            .map(|field| field.data_type().clone())
+            .collect();
+        let signature = Signature::exact(signature_types, volatility);
+        Self {
+            name: name.into(),
+            signature,
+            return_field: Arc::new(return_field),
+            fun: fun.into(),
+        }
+    }
+}
+
+impl ScalarUDFImpl for PySimpleScalarUDF {
+    fn as_any(&self) -> &dyn std::any::Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        &self.name
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, _arg_types: &[DataType]) -> 
datafusion::error::Result<DataType> {
+        Ok(self.return_field.data_type().clone())

Review Comment:
   Omitting implementation prevents compilation.
   
   ```
   error[E0046]: not all trait items implemented, missing: `return_type`
      --> src/udf.rs:124:1
       |
   124 | impl ScalarUDFImpl for PySimpleScalarUDF {
       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `return_type` in 
implementation
   ```
   I amended it to return
   ```rust
   Err(DataFusionError::Internal(
     "return_type should be unreachable when return_field_from_args is 
implemented"
       .to_string(),
   ```
   



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