Skip to content

Conversation

@ueshin
Copy link
Member

@ueshin ueshin commented Aug 14, 2023

What changes were proposed in this pull request?

This is a follow-up of #42422.

Adds more tests for named arguments in Python UDTF.

Why are the changes needed?

There are more cases to test.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added related tests.

@ueshin
Copy link
Member Author

ueshin commented Aug 14, 2023

cc @allisonwang-db

Copy link
Contributor

@dtenedor dtenedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if @allisonwang-db agrees 👍

Copy link
Contributor

@allisonwang-db allisonwang-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the follow-up PR.

@udtf
class TestUDTF:
@staticmethod
def analyze(a, b=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If b is a parameter with a default value (e.g 100), do we need to also assign a default value (e.g. None) here in the analyze method? If we directly use def analyze(a, b) does it throw an exception?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if b here doesn't have a default value, it will raise an exception.

Both eval and analyze will be called with the same argument list.
So if eval takes a, analyze should also take a, if eval takes a, b, analyze should also take a, b, and so on.

It can be AnalyzeArgument with the correct parameters, or take **kwargs.

def analyze(a, b=AnalyzeArgument(StringType(), None, False)):
def analyze(a, **kwargs):

but taking AnalyzeArgument as default is not recommended if the data_type is a struct type, which could cause unexpected behavior similar to taking [] or {} as default.

@ueshin
Copy link
Member Author

ueshin commented Aug 15, 2023

Thanks! merging to master.

@ueshin ueshin closed this in f7002fb Aug 15, 2023
valentinp17 pushed a commit to valentinp17/spark that referenced this pull request Aug 24, 2023
…ents in Python UDTF

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

This is a follow-up of apache#42422.

Adds more tests for named arguments in Python UDTF.

### Why are the changes needed?

There are more cases to test.

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

No.

### How was this patch tested?

Added related tests.

Closes apache#42490 from ueshin/issues/SPARK-44749/tests.

Authored-by: Takuya UESHIN <[email protected]>
Signed-off-by: Takuya UESHIN <[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.

3 participants