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

Convert more unary functions #11805

Merged
merged 7 commits into from
Apr 19, 2022
Merged

Conversation

petrosagg
Copy link
Contributor

Motivation

Testing

  • This PR has adequate test coverage / QA involvement has been duly considered.

Release notes

This PR includes the following user-facing behavior changes:

@petrosagg petrosagg force-pushed the more-unary-func branch 2 times, most recently from 990d4da to a2f5478 Compare April 14, 2022 22:04
Copy link
Contributor

@aalexandrov aalexandrov left a comment

Choose a reason for hiding this comment

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

Looks good.

sqlfunc!(
#[sqlname = "octet_length"]
fn byte_length_bytes<'a>(a: &'a [u8]) -> Result<i32, EvalError> {
i32::try_from(a.len()).or(Err(EvalError::Int32OutOfRange))
Copy link
Contributor

Choose a reason for hiding this comment

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

I am often confused when I should use or vs or_else. Will the cost of constructing Err(EvalError::Int32OutOfRange) be amortized somehow during compilation time because the expression is constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's exactly the intuition

Copy link
Contributor Author

@petrosagg petrosagg Apr 19, 2022

Choose a reason for hiding this comment

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

Also see this relevant clippy discussion on whether any const function should be allowed in an .or(..) (the answer is no) rust-lang/rust-clippy#5658

#[derive(Ord, PartialOrd, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash, MzReflect)]
pub struct JsonbStripNulls;

impl LazyUnaryFunc for JsonbStripNulls {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the aspect of JsonbStripNulls that prohibits from using sqlfunc! in favor of impl LazyUnaryFunc?
Is it just the fact that sqlfunc! hard-codes an EagerUnaryFunc implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just allows it to re-use the temporary_storage which is more efficient but I switched it now to sqlfunc! which is a lot simpler

…ions

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Copy link
Contributor

@sploiselle sploiselle left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
@petrosagg petrosagg merged commit fc1988f into MaterializeInc:main Apr 19, 2022
@petrosagg petrosagg deleted the more-unary-func branch April 19, 2022 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants