dtenedor commented on code in PR #43611:
URL: https://github.com/apache/spark/pull/43611#discussion_r1396192258


##########
python/pyspark/sql/worker/analyze_udtf.py:
##########
@@ -116,12 +118,150 @@ def main(infile: IO, outfile: IO) -> None:
         handler = read_udtf(infile)
         args, kwargs = read_arguments(infile)
 
+        error_prefix = f"Failed to evaluate the user-defined table function 
'{handler.__name__}'"
+
+        def format_error(msg: str) -> str:
+            return dedent(msg).replace("\n", " ")
+
+        # Check invariants about the 'analyze' and 'eval' methods before 
running them.
+        def check_method_invariants_before_running(
+            expected: inspect.FullArgSpec, method: str, is_static: bool
+        ) -> None:
+            num_expected_args = len(expected.args)
+            num_provided_args = len(args) + len(kwargs)
+            num_provided_non_kw_args = len(args)
+            if not is_static:
+                num_provided_args += 1
+                num_provided_non_kw_args += 1
+            if (
+                expected.varargs is None
+                and expected.varkw is None
+                and expected.defaults is None
+                and num_expected_args != num_provided_args
+            ):
+                # The UDTF call provided the wrong number of positional 
arguments.
+                def arguments(num: int) -> str:
+                    return f"{num} argument{'' if num == 1 else 's'}"
+
+                raise PySparkValueError(
+                    format_error(
+                        f"""
+                    {error_prefix} because its '{method}' method expects 
exactly

Review Comment:
   I thought so as well, but the `dev/reformat-python` script keeps changing it 
back to this :) 



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