Skip to content

Conversation

@cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

This PR refactors TryCast to use RuntimeReplaceable, so that we don't need CastBase anymore. The unit tests are also simplified because we don't need to check the execution of RuntimeReplaceable, but only the analysis behavior.

Why are the changes needed?

code cleanup

Does this PR introduce any user-facing change?

no

How was this patch tested?

existing tests

@github-actions github-actions bot added the SQL label May 27, 2022
@cloud-fan cloud-fan force-pushed the cast branch 2 times, most recently from d1695e6 to 58bf9dd Compare May 31, 2022 15:38
@cloud-fan
Copy link
Contributor Author

cc @gengliangwang @beliefer

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the fix.

@MaxGekk
Copy link
Member

MaxGekk commented Jun 7, 2022

@cloud-fan Could you resolve conflicts, please.

Copy link
Member

Choose a reason for hiding this comment

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

I am confused. The default value of USER_SPECIFIED_CAST seems to be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

USER_SPECIFIED_CAST is a TreeNodeTag that is only used by Cast, we don't need to set it in TryCast. Let me improve the comment.

Copy link
Member

@gengliangwang gengliangwang left a comment

Choose a reason for hiding this comment

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

Thanks for the refactoring!

@cloud-fan
Copy link
Contributor Author

thanks for the review, merging to master!

@cloud-fan cloud-fan closed this in 46175d1 Jun 8, 2022
gengliangwang added a commit that referenced this pull request Aug 12, 2022
### What changes were proposed in this pull request?

For the following query
```
SET spark.sql.ansi.enabled=true;
SELECT try_cast(1/0 AS string);
```
Spark 3.3 will throw an exception for the division by zero error. In the current master branch, it returns null after the refactoring PR #36703

This PR is to restore the previous error handling syntax.

### Why are the changes needed?

1. Restore the behavior of try_cast()
2. The previous syntax is more reasonable. Users can cleanly catch the exception from the child of `try_cast`.

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

No
### How was this patch tested?

Unit tests

Closes #37486 from gengliangwang/restoreTryCast.

Authored-by: Gengliang Wang <[email protected]>
Signed-off-by: Gengliang Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants