-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-49538][SQL][TESTS] Detect unused error message parameters #48026
Conversation
@@ -6222,7 +6222,7 @@ | |||
"Detected implicit cartesian product for <joinType> join between logical plans", | |||
"<leftPlan>", | |||
"and", | |||
"rightPlan", | |||
"<rightPlan>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of this PR is to detect mistakes like this.
"Query [id = <id>, runId = <runId>, startOffset = <startOffset>, endOffset = <endOffset>] terminated with exception: <message>", | ||
"<queryDebugString>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HeartSaVioR Could you look at the changes, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be slightly messed up -
This class overrides getMessage and handles queryDebugString separately. So it's expected to not have queryDebugString here.
What I'm confused is why we have a case where queryDebugString is passed over message parameters, since we have constructors which directly receive queryDebugString.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's expected to not have queryDebugString here.
@HeartSaVioR ok, let me remove it from message parameters and from the error format. How about other 2 unused parameters: startOffset
and endOffset
. Does queryDebugString
include the info, it seems?
private def toDebugString(includeLogicalPlan: Boolean): String = {
val debugString =
s"""|=== Streaming Query ===
|Identifier: $prettyIdString
|Current Committed Offsets: ${getLatestExecutionContext().startOffsets}
|Current Available Offsets: ${getLatestExecutionContext().endOffsets}
@srielau Please, have a look at the PR. |
"queryDebugString" -> toDebugString(includeLogicalPlan = isInitialized), | ||
"startOffset" -> getLatestExecutionContext().startOffsets.toOffsetSeq( | ||
sources.toSeq, getLatestExecutionContext().offsetSeqMetadata).toString, | ||
"endOffset" -> getLatestExecutionContext().endOffsets.toOffsetSeq( | ||
sources.toSeq, getLatestExecutionContext().offsetSeqMetadata).toString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @HeartSaVioR mentioned in a comment, the parameters are included in message
in some circumstances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah not sure why this passed through params as we have params in constructor. Thanks for fixing this!
@@ -7827,7 +7827,7 @@ | |||
}, | |||
"_LEGACY_ERROR_TEMP_3055" : { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If we're already touching this _LEGACY, could we just name it? (is this an internal error??)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened the starter task https://issues.apache.org/jira/browse/SPARK-49549 @mitkedb FYI.
@HeartSaVioR Do you have any objections for the changes? |
@@ -904,7 +904,7 @@ | |||
}, | |||
"NON_STRING_TYPE" : { | |||
"message" : [ | |||
"all arguments must be strings." | |||
"all arguments of the function <funcName> must be strings." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Merging to master. Thank you, @HeartSaVioR @srielau @allisonwang-db @HyukjinKwon for review. |
…Class` in `SparkThrowableSuite` and in `DateTimeFormatterHelperSuite` ### What changes were proposed in this pull request? In the PR, I propose to use `condition` instead of `errorClass` in two test suites: - SparkThrowableSuite - DateTimeFormatterHelperSuite ### Why are the changes needed? Because the changes from the PR #48027 conflict to #48058 and #48026, and tests in #48027 were passed earlier than the last PRs were merged to master. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By compiling and running the following tests locally: ``` $ build/sbt "test:testOnly *org.apache.spark.sql.catalyst.util.DateTimeFormatterHelperSuite" $ build/sbt "test:testOnly *SparkThrowableSuite" ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #48061 from MaxGekk/fix-missing-errorClass. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
### What changes were proposed in this pull request? In the PR, I propose to detect unused error message parameters while substituting placeholders in error message formats, and raise an internal error in tests when the number of parameters is greater than the number of placeholders. That might indicate presence of unused message parameters. ### Why are the changes needed? Might happens that the passed error message parameters and placeholders in message format are not matched, and contain extra items. From the code maintainability perspective, it would be nice to detect such cases while running tests. For example, the error message format could look like: ```json "CANNOT_UP_CAST_DATATYPE" : { "message" : [ "Cannot up cast <expression> from <sourceType> to <targetType>.", "<details>" ], "sqlState" : "42846" }, ``` but the passed message parameters have extra parameter: ```scala messageParameters = Map( "expression" -> "CAST('aaa' AS LONG)", "sourceType" -> "STRING", "targetType" -> "LONG", "op" -> "CAST", // unused parameter "details" -> "implicit cast" )) ``` This can happen because: - tech editor/dev forgot to mention some parameters in error message format, - wrong usage of error conditions/sub-conditions - source code became outdated - typos in error message formats ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By running the added test via: ``` $ build/mvn -Dtest=none -DwildcardSuites=org.apache.spark.SparkThrowableSuite test ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48026 from MaxGekk/detect-unused-error-params. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
…Class` in `SparkThrowableSuite` and in `DateTimeFormatterHelperSuite` ### What changes were proposed in this pull request? In the PR, I propose to use `condition` instead of `errorClass` in two test suites: - SparkThrowableSuite - DateTimeFormatterHelperSuite ### Why are the changes needed? Because the changes from the PR apache#48027 conflict to apache#48058 and apache#48026, and tests in apache#48027 were passed earlier than the last PRs were merged to master. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By compiling and running the following tests locally: ``` $ build/sbt "test:testOnly *org.apache.spark.sql.catalyst.util.DateTimeFormatterHelperSuite" $ build/sbt "test:testOnly *SparkThrowableSuite" ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48061 from MaxGekk/fix-missing-errorClass. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
### What changes were proposed in this pull request? In the PR, I propose to detect unused error message parameters while substituting placeholders in error message formats, and raise an internal error in tests when the number of parameters is greater than the number of placeholders. That might indicate presence of unused message parameters. ### Why are the changes needed? Might happens that the passed error message parameters and placeholders in message format are not matched, and contain extra items. From the code maintainability perspective, it would be nice to detect such cases while running tests. For example, the error message format could look like: ```json "CANNOT_UP_CAST_DATATYPE" : { "message" : [ "Cannot up cast <expression> from <sourceType> to <targetType>.", "<details>" ], "sqlState" : "42846" }, ``` but the passed message parameters have extra parameter: ```scala messageParameters = Map( "expression" -> "CAST('aaa' AS LONG)", "sourceType" -> "STRING", "targetType" -> "LONG", "op" -> "CAST", // unused parameter "details" -> "implicit cast" )) ``` This can happen because: - tech editor/dev forgot to mention some parameters in error message format, - wrong usage of error conditions/sub-conditions - source code became outdated - typos in error message formats ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By running the added test via: ``` $ build/mvn -Dtest=none -DwildcardSuites=org.apache.spark.SparkThrowableSuite test ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48026 from MaxGekk/detect-unused-error-params. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
…Class` in `SparkThrowableSuite` and in `DateTimeFormatterHelperSuite` ### What changes were proposed in this pull request? In the PR, I propose to use `condition` instead of `errorClass` in two test suites: - SparkThrowableSuite - DateTimeFormatterHelperSuite ### Why are the changes needed? Because the changes from the PR apache#48027 conflict to apache#48058 and apache#48026, and tests in apache#48027 were passed earlier than the last PRs were merged to master. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By compiling and running the following tests locally: ``` $ build/sbt "test:testOnly *org.apache.spark.sql.catalyst.util.DateTimeFormatterHelperSuite" $ build/sbt "test:testOnly *SparkThrowableSuite" ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48061 from MaxGekk/fix-missing-errorClass. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
What changes were proposed in this pull request?
In the PR, I propose to detect unused error message parameters while substituting placeholders in error message formats, and raise an internal error in tests when the number of parameters is greater than the number of placeholders. That might indicate presence of unused message parameters.
Why are the changes needed?
Might happens that the passed error message parameters and placeholders in message format are not matched, and contain extra items. From the code maintainability perspective, it would be nice to detect such cases while running tests.
For example, the error message format could look like:
but the passed message parameters have extra parameter:
This can happen because:
Does this PR introduce any user-facing change?
No.
How was this patch tested?
By running the added test via:
Was this patch authored or co-authored using generative AI tooling?
No.