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

Add function volatility to Signature #1071

Merged
merged 8 commits into from
Oct 7, 2021
Merged

Conversation

pjmore
Copy link
Contributor

@pjmore pjmore commented Oct 5, 2021

Which issue does this PR close?

Closes #1069.

Rationale for this change

Make volatility a first class concept for functions.

What changes are included in this PR?

Renamed the Signature enum to TypeSignature and added Signature struct which currently has 2 fields, type_signature and volatility. I initially tried adding another field containing the volatility to the original Signature enum but this felt clunky and while it could potential allow for conditionally stable\immutable functions with the OneOf variant that seemed like a fairly niche optimization.

Are there any user-facing changes?

Yes Signature was renamed and volatility has been added. There are breaking changes to the public API from this, could someone add the api-break label? I don't have permission to add labels.

@github-actions github-actions bot added datafusion Changes in the datafusion crate python sql SQL Planner labels Oct 5, 2021
Copy link
Member

@houqp houqp left a comment

Choose a reason for hiding this comment

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

Great work @pjmore !

@houqp houqp added the api change Changes the API exposed to users of the crate label Oct 5, 2021
Copy link
Member

@jorgecarleitao jorgecarleitao left a comment

Choose a reason for hiding this comment

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

Beautiful. Ready to go imo.

@alamb alamb changed the title Function volatility Add function volatility to Signature Oct 6, 2021
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

I agree with other reviewers that the code structure of this PR is very nice. Thank you @pjmore

It appears to be failing two lint CI checks -- but I think that simply needs a cargo fmt and and black --line-length 79 python and it will be good to go

Thanks a lot @pjmore !

BuiltinScalarFunction::Upper => Volatility::Immutable,
BuiltinScalarFunction::RegexpMatch => Volatility::Immutable,

//Stable builtin functions
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -81,7 +81,7 @@ def test_limit(df):

def test_udf(df):
# is_null is a pa function over arrays
udf = f.udf(lambda x: x.is_null(), [pa.int64()], pa.bool_())
udf = f.udf(lambda x: x.is_null(), [pa.int64()], pa.bool_(), f.Volatility.immutable())
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this line is causing the python code formatter to fail

You can fix it by running a command such as the following

cd datafusion
black --line-length 79 python

@alamb
Copy link
Contributor

alamb commented Oct 7, 2021

Thanks again @pjmore !

@alamb alamb merged commit 4687899 into apache:master Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate datafusion Changes in the datafusion crate sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark volatility categories of functions
4 participants