fdolce commented on code in PR #29146:
URL: https://github.com/apache/flink/pull/29146#discussion_r3989642004


##########
flink-python/pyflink/dataframe/sql.py:
##########
@@ -33,49 +34,61 @@
 
 _LOG = logging.getLogger(__name__)
 
+_Binding = Union[DataFrame, _DataFrameUDFWrapper]

Review Comment:
   Ok, looking a bit more into it, we've got a couple of options:
   - As you suggest, we make `pf.udf` return `_DataFrameUDFWrapper`. This is 
easiest, but then you'd see a private class as the return type, and I think we 
should avoid this. So if we go this way, I'd probably rename that to `UDF` and 
make it public properly, but it's a bigger change.
   - An alternative to avoid making the whole class public, is to use a 
`Protocol`. We create a `class UDF(Protocol)` that requires `def __call__(...) 
-> Expression` and `def return_dtype(...) -> DataType` and export that as 
public api, used only for type checking. This is what pyspark does. Still not a 
trivial change to add to this PR but...
   - I could modify `_Binding` to be `Union[DataFrame, Callable[..., 
Expression]]`, leave `_BINDABLE_TYPES` as it is. This way any function that 
returns an Expression is ok for the static checker (because `sql` annotations 
matches what `udf` declares), but if it's not a real `_DataFramUDFWrapper` it's 
rejected at runtime only. It's a minimal change here, removes the false 
negative (in exchange of possible false positives at static check time), and 
can be transformed into one of the other 2 solutions in a separate PR.
   
   I'm going to commit this last one as the minimal solution in a separate 
commit, but let me know if you prefer otherwise, I'll change it



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

Reply via email to