Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-48938][PYTHON] Improve error messages when registering Python UDTFs #47408

Conversation

allisonwang-db
Copy link
Contributor

@allisonwang-db allisonwang-db commented Jul 18, 2024

What changes were proposed in this pull request?

This PR improves the error messages when registering Python UDTFs.
Before this PR:

class TestUDTF:
   ...

spark.udtf.register("test_udtf", TestUDTF)

This fails with

AttributeError: type object "TestUDTF" has no attribute "evalType"

After this PR:

spark.udtf.register("test_udtf", TestUDTF)

Now we have a nicer error:

[CANNOT_REGISTER_UDTF] Cannot register the UDTF 'test_udtf': expected a 'UserDefinedTableFunction'. Please make sure the UDTF is correctly defined as a class, and then either wrap it in the `udtf()` function or annotate it with `@udtf(...)`.`

Why are the changes needed?

To improve usability.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Existing and new unit tests.

Was this patch authored or co-authored using generative AI tooling?

No

@allisonwang-db
Copy link
Contributor Author

cc @ueshin

@HyukjinKwon
Copy link
Member

Merged to master.

jingz-db pushed a commit to jingz-db/spark that referenced this pull request Jul 22, 2024
…UDTFs

### What changes were proposed in this pull request?

This PR improves the error messages when registering Python UDTFs.
Before this PR:
```python
class TestUDTF:
   ...

spark.udtf.register("test_udtf", TestUDTF)
```
This fails with
```
AttributeError: type object "TestUDTF" has no attribute "evalType"
```
After this PR:
```python
spark.udtf.register("test_udtf", TestUDTF)
```
Now we have a nicer error:
```
[CANNOT_REGISTER_UDTF] Cannot register the UDTF 'test_udtf': expected a 'UserDefinedTableFunction'. Please make sure the UDTF is correctly defined as a class, and then either wrap it in the `udtf()` function or annotate it with `udtf(...)`.`
```

### Why are the changes needed?

To improve usability.

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Existing and new unit tests.

### Was this patch authored or co-authored using generative AI tooling?

No

Closes apache#47408 from allisonwang-db/spark-48938-udtf-register-err-msg.

Authored-by: allisonwang-db <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
attilapiros pushed a commit to attilapiros/spark that referenced this pull request Oct 4, 2024
…UDTFs

### What changes were proposed in this pull request?

This PR improves the error messages when registering Python UDTFs.
Before this PR:
```python
class TestUDTF:
   ...

spark.udtf.register("test_udtf", TestUDTF)
```
This fails with
```
AttributeError: type object "TestUDTF" has no attribute "evalType"
```
After this PR:
```python
spark.udtf.register("test_udtf", TestUDTF)
```
Now we have a nicer error:
```
[CANNOT_REGISTER_UDTF] Cannot register the UDTF 'test_udtf': expected a 'UserDefinedTableFunction'. Please make sure the UDTF is correctly defined as a class, and then either wrap it in the `udtf()` function or annotate it with `udtf(...)`.`
```

### Why are the changes needed?

To improve usability.

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Existing and new unit tests.

### Was this patch authored or co-authored using generative AI tooling?

No

Closes apache#47408 from allisonwang-db/spark-48938-udtf-register-err-msg.

Authored-by: allisonwang-db <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants