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

ImproveSignature and comparison_coercion documentation #13840

Merged
merged 3 commits into from
Dec 20, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Dec 19, 2024

Which issue does this PR close?

Rationale for this change

While improving the docs in #13817, @findepi identified additional areas that were not super clear

What changes are included in this PR?

Try to improve the documentation about coercion more.

Are these changes tested?

By doc CI tests

Are there any user-facing changes?

Better docs, no functional change

@alamb alamb added the documentation Improvements or additions to documentation label Dec 19, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 19, 2024
/// since i32 and f32 can be cast to f64
///
/// For functions that take no arguments (e.g. `random()`) see [`TypeSignature::Nullary`].
Coercible(Vec<TypeSignatureClass>),
/// One or more arguments that can be "compared"
/// One or more arguments cast to single, comparable type.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is clearer and correct, though I would appreciate it if @jayzhan211 could double check

@alamb alamb changed the title Improve Signature documentation more ImproveSignature and comparison_coercion documentation Dec 19, 2024
Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

💯

Thanks @alamb

datafusion/expr-common/src/signature.rs Outdated Show resolved Hide resolved
datafusion/expr-common/src/signature.rs Outdated Show resolved Hide resolved
/// One or more arguments cast to single, comparable type.
///
/// Each argument will be coerced to a single type using the
/// coercion rules described in [`comparison_coercion_numeric`].
Copy link
Member

Choose a reason for hiding this comment

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

Why numeric? Strings are also comparable

Copy link
Contributor

@jayzhan211 jayzhan211 Dec 19, 2024

Choose a reason for hiding this comment

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

yes, but we have numeric currently, update doc when code is updated to be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree -- this code could be improved / named better. I looked at the implementation and there are quite a few differences between comparison_coercion_numeric and comparison_coercion that I didn't understand and thus didn't attempt to document

It would be great if someone could

/// - For functions that take no arguments (e.g. `random()` see [`TypeSignature::Nullary`]).
/// - If all arguments have type [`DataType::Null`], they are coerced to `Utf8`
Copy link
Member

Choose a reason for hiding this comment

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

ouch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am just documenting what I think the code does 🤷 -- I agree this area of the code could be improved

Copy link
Contributor

Choose a reason for hiding this comment

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

To fix this, we might need to find a way to differentiate string literal as unknown type v.s. string type. Not yet have time to investigate on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In some magic ideal world where I had infinite time, I have dreamed about refactor the coercion code into a set of structs that encoded the rules in a more structured / composable manner. But I don't have time to pursue that dream at this time 🏃

@alamb alamb merged commit 87b77bb into apache:main Dec 20, 2024
24 checks passed
@alamb
Copy link
Contributor Author

alamb commented Dec 20, 2024

Thanks again @findepi and @jayzhan211

@alamb alamb deleted the alamb/better_sig_docs branch December 20, 2024 14:32
@alamb alamb added the documentation Improvements or additions to documentation label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants