You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "comphead (via GitHub)" <gi...@apache.org> on 2023/07/27 15:33:29 UTC
[GitHub] [arrow-datafusion] comphead opened a new pull request, #7115: Dev
comphead opened a new pull request, #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
Related to #6740.
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb merged pull request #7115: Add `plan_err!` error macro
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281203423
##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
}
}
+/// Unwrap an `Option` if possible. Otherwise return an `DataFusionError::Internal`.
+/// In normal usage of DataFusion the unwrap should always succeed.
+///
+/// Example: `let values = unwrap_or_internal_err!(values)`
+#[macro_export]
+macro_rules! unwrap_or_internal_err {
+ ($Value: ident) => {
+ $Value.ok_or_else(|| {
+ DataFusionError::Internal(format!(
+ "{} should not be None",
+ stringify!($Value)
+ ))
+ })?
+ };
+}
+
+#[macro_export]
+macro_rules! with_dollar_sign {
+ ($($body:tt)*) => {
+ macro_rules! __with_dollar_sign { $($body)* }
+ __with_dollar_sign!($);
+ }
+}
Review Comment:
Interesting, I thought the macros with same name even not exposed will conflict each other.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] comphead commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281178198
##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
}
}
+/// Unwrap an `Option` if possible. Otherwise return an `DataFusionError::Internal`.
+/// In normal usage of DataFusion the unwrap should always succeed.
+///
+/// Example: `let values = unwrap_or_internal_err!(values)`
+#[macro_export]
+macro_rules! unwrap_or_internal_err {
+ ($Value: ident) => {
+ $Value.ok_or_else(|| {
+ DataFusionError::Internal(format!(
+ "{} should not be None",
+ stringify!($Value)
+ ))
+ })?
+ };
+}
+
+#[macro_export]
+macro_rules! with_dollar_sign {
+ ($($body:tt)*) => {
+ macro_rules! __with_dollar_sign { $($body)* }
+ __with_dollar_sign!($);
+ }
+}
Review Comment:
it doesn't conflict, but if you expand macros in
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e5aad70ec87a420a6d4c9a7ba023c56d
you can see `__with_dollar_sign` created twice, but since the macro is not exported it is okay
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] comphead commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281139378
##########
datafusion/physical-expr/src/functions.rs:
##########
@@ -2843,16 +2844,16 @@ mod tests {
match expr {
Ok(..) => {
- return Err(DataFusionError::Plan(format!(
+ return plan_err!(
"Builtin scalar function {fun} does not support empty arguments"
- )));
+ );
}
Err(DataFusionError::Plan(err)) => {
if !err
.contains("No function matches the given name and argument types")
{
- return Err(DataFusionError::Internal(format!(
- "Builtin scalar function {fun} didn't got the right error message with empty arguments")));
+ return plan_err!(
Review Comment:
it handles the condition related to
```
Err(DataFusionError::Plan(err))
```
thus its likely more related to plan than to Internal
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] comphead commented on pull request #7115: RFC: add error macros
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#issuecomment-1654582565
> I think this PR looks really cool @comphead - the new macro seems to save a lot of boiler plate and is quite clear in my mind
Cool, thanks for the feedback, will be covering all other plan references
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281092037
##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
}
}
+/// Unwrap an `Option` if possible. Otherwise return an `DataFusionError::Internal`.
Review Comment:
👍 very nice
##########
datafusion/core/tests/sql/mod.rs:
##########
@@ -405,10 +406,7 @@ async fn register_tpch_csv_data(
DataType::Decimal128(_, _) => {
cols.push(Box::new(Decimal128Builder::with_capacity(records.len())))
}
- _ => {
- let msg = format!("Not implemented: {}", field.data_type());
- Err(DataFusionError::Plan(msg))?
- }
+ _ => plan_err!("Not implemented: {}", field.data_type())?,
Review Comment:
This change didn't introduce this strangeness, but this should probably be "NotImplemented" rather than a PlanError
##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
}
}
+/// Unwrap an `Option` if possible. Otherwise return an `DataFusionError::Internal`.
Review Comment:
👍 very nice
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281131479
##########
datafusion/common/src/error.rs:
##########
@@ -510,26 +581,3 @@ mod test {
assert_eq!(std::mem::discriminant(e), std::mem::discriminant(&exp),)
}
}
-
-#[macro_export]
-macro_rules! internal_err {
- ($($arg:tt)*) => {
- Err(DataFusionError::Internal(format!($($arg)*)))
- };
-}
Review Comment:
This is removed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] comphead commented on pull request #7115: Dev
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#issuecomment-1653864105
@alamb I went through some use cases for replacing plan errors with macro. Going fwd we can add to the macro `file!`, `line!` macros to let user know the exact cause of the error. Please let me know your thoughts on this direction
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281133286
##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
}
}
+/// Unwrap an `Option` if possible. Otherwise return an `DataFusionError::Internal`.
+/// In normal usage of DataFusion the unwrap should always succeed.
+///
+/// Example: `let values = unwrap_or_internal_err!(values)`
+#[macro_export]
+macro_rules! unwrap_or_internal_err {
+ ($Value: ident) => {
+ $Value.ok_or_else(|| {
+ DataFusionError::Internal(format!(
+ "{} should not be None",
+ stringify!($Value)
+ ))
+ })?
+ };
+}
+
+#[macro_export]
+macro_rules! with_dollar_sign {
+ ($($body:tt)*) => {
+ macro_rules! __with_dollar_sign { $($body)* }
+ __with_dollar_sign!($);
+ }
+}
+
+/// Add a macros for concise DataFusionError::* errors declaration
+/// supports placeholders the same way as `format!`
+/// Examples:
+/// plan_err!("Error")
+/// plan_err!("Error {}", val)
+/// plan_err!("Error {:?}", val)
+/// plan_err!("Error {val}")
+/// plan_err!("Error {val:?}")
+macro_rules! make_error {
+ ($NAME:ident, $ERR:ident) => {
+ with_dollar_sign! {
+ ($d:tt) => {
+ #[macro_export]
+ macro_rules! $NAME {
+ ($d($d args:expr),*) => {
+ Err(DataFusionError::$ERR(format!($d($d args),*).into()))
+ }
+ }
+ }
+ }
+ };
+}
+
+// DataFusionError::Plan
+make_error!(plan_err, Plan);
Review Comment:
```suggestion
// Exposes a macro to create `DataFusionError::Plan`
make_error!(plan_err, Plan);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281130587
##########
datafusion/physical-expr/src/functions.rs:
##########
@@ -2843,16 +2844,16 @@ mod tests {
match expr {
Ok(..) => {
- return Err(DataFusionError::Plan(format!(
+ return plan_err!(
"Builtin scalar function {fun} does not support empty arguments"
- )));
+ );
}
Err(DataFusionError::Plan(err)) => {
if !err
.contains("No function matches the given name and argument types")
{
- return Err(DataFusionError::Internal(format!(
- "Builtin scalar function {fun} didn't got the right error message with empty arguments")));
+ return plan_err!(
Review Comment:
Does this change from Internal error to Plan error?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] comphead commented on pull request #7115: RFC: add error macros
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#issuecomment-1659597926
@alamb went through all `Err(DatafusionError::Plan)` entries. There are still few entries like `DatafusionError::Plan` in `ok_or_else` or `map_err`, I will prob generate a separate macros for such case.
Thanks for checking the PR before the code rots
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on pull request #7115: Add error macros
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#issuecomment-1660989157
<img width="158" alt="Screenshot 2023-08-01 at 3 55 59 PM" src="https://github.com/apache/arrow-datafusion/assets/490673/4168a48f-d513-49cb-a80b-e661492d9ab1">
very nice @comphead 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281143181
##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
}
}
+/// Unwrap an `Option` if possible. Otherwise return an `DataFusionError::Internal`.
+/// In normal usage of DataFusion the unwrap should always succeed.
+///
+/// Example: `let values = unwrap_or_internal_err!(values)`
+#[macro_export]
+macro_rules! unwrap_or_internal_err {
+ ($Value: ident) => {
+ $Value.ok_or_else(|| {
+ DataFusionError::Internal(format!(
+ "{} should not be None",
+ stringify!($Value)
+ ))
+ })?
+ };
+}
+
+#[macro_export]
+macro_rules! with_dollar_sign {
+ ($($body:tt)*) => {
+ macro_rules! __with_dollar_sign { $($body)* }
+ __with_dollar_sign!($);
+ }
+}
Review Comment:
Hmm, does it define a macro `__with_dollar_sign` every time `with_dollar_sign` is called? If we call `make_error` multiple times (e.g., to define macro for other error type), does it conflict?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281143181
##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
}
}
+/// Unwrap an `Option` if possible. Otherwise return an `DataFusionError::Internal`.
+/// In normal usage of DataFusion the unwrap should always succeed.
+///
+/// Example: `let values = unwrap_or_internal_err!(values)`
+#[macro_export]
+macro_rules! unwrap_or_internal_err {
+ ($Value: ident) => {
+ $Value.ok_or_else(|| {
+ DataFusionError::Internal(format!(
+ "{} should not be None",
+ stringify!($Value)
+ ))
+ })?
+ };
+}
+
+#[macro_export]
+macro_rules! with_dollar_sign {
+ ($($body:tt)*) => {
+ macro_rules! __with_dollar_sign { $($body)* }
+ __with_dollar_sign!($);
+ }
+}
Review Comment:
Hmm, does it define a macro `__with_dollar_sign` every time `with_dollar_sign` is called? If we call `make_error` multiple times, does it conflict?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] comphead commented on a diff in pull request #7115: Add `plan_err!` error macro
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281135178
##########
datafusion/common/src/error.rs:
##########
@@ -510,26 +581,3 @@ mod test {
assert_eq!(std::mem::discriminant(e), std::mem::discriminant(&exp),)
}
}
-
-#[macro_export]
-macro_rules! internal_err {
- ($($arg:tt)*) => {
- Err(DataFusionError::Internal(format!($($arg)*)))
- };
-}
Review Comment:
Its not used by anyone, instead new macro will be create for internal errors
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on pull request #7115: Add `plan_err!` error macro
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#issuecomment-1663921720
Thanks again @comphead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org