Skip to content

Conversation

@MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Dec 22, 2023

What changes were proposed in this pull request?

In the PR, I propose to create SparkThrowable sub-classes only with an error class by making the constructor with message private.

Why are the changes needed?

To improve user experience with Spark SQL by unifying error exceptions: the final goal is all Spark exception should contain an error class.

Does this PR introduce any user-facing change?

No since user's code shouldn't throw SparkThrowable sub-classes but it can if it depends on error message formats.

How was this patch tested?

By existing test test suites like:

$ PYSPARK_PYTHON=python3 build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"

Was this patch authored or co-authored using generative AI tooling?

No.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

Could you make the CI happy? The failure messages seem to be related.

@MaxGekk
Copy link
Member Author

MaxGekk commented Dec 26, 2023

I am trying to fix some issues in the PR #44468. So far, will convert this PR to a draft.

@MaxGekk MaxGekk marked this pull request as draft December 26, 2023 19:59
@MaxGekk MaxGekk changed the title [SPARK-46490][SQL] Require error classes in SparkThrowable sub-classes [WIP][SPARK-46490][SQL] Require error classes in SparkThrowable sub-classes Dec 26, 2023
params.errorClass.orNull,
params.messageParameters,
params.queryContext)),
errorConstructor[NumberFormatException](params =>
Copy link
Member Author

Choose a reason for hiding this comment

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

Before this PR, we converted Java exception to Spark exception at the client side by passing the message as is (error class and message parameters was null or empty) like: NumberFormatException("invalid format 9hh99") -> SparkNumberFormatException("invalid format 9hh99", errorClass = null).

After the changes, the conversion still exists but I put the original message to a parameter:
NumberFormatException("invalid format 9hh99") -> SparkNumberFormatException(errorClass = "_LEGACY_ERROR_TEMP_3104", messageParameters = Map("message" -> "invalid format 9hh99"))

Copy link
Member Author

@MaxGekk MaxGekk Dec 29, 2023

Choose a reason for hiding this comment

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

Eventually, we should convert all Java exceptions to Spark exceptions but since Spark SQL still raises such exceptions, different error class will allow to identify which Java exceptions haven't been ported yet.

@MaxGekk MaxGekk marked this pull request as ready for review December 29, 2023 10:42
@MaxGekk MaxGekk changed the title [WIP][SPARK-46490][SQL] Require error classes in SparkThrowable sub-classes [SPARK-46490][SQL] Require error classes in SparkThrowable sub-classes Dec 29, 2023
@MaxGekk
Copy link
Member Author

MaxGekk commented Dec 29, 2023

@cloud-fan @dongjoon-hyun @HyukjinKwon @heyihong Please, review this PR.

@dongjoon-hyun
Copy link
Member

Could you make the CI successful, @MaxGekk ?

@MaxGekk
Copy link
Member Author

MaxGekk commented Dec 29, 2023

@dongjoon-hyun I guess Run / Run Spark on Kubernetes Integration test is not related to the changes, but I re-ran it again. I am observing the same failure in other PRs.

Copy link
Contributor

@heyihong heyihong left a comment

Choose a reason for hiding this comment

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

LGTM with one nit

Copy link
Contributor

@heyihong heyihong left a comment

Choose a reason for hiding this comment

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

On a second look, we may need some logics to handle cases that error classes are actually set

params.queryContext)),
errorConstructor[NumberFormatException](params =>
new SparkNumberFormatException(
errorClass = "_LEGACY_ERROR_TEMP_3104",
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this may need some special handling since params.errorClass and params.messageParameters may be set

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe

errorClass = params.errorClass.orElse("_LEGACY_ERROR_TEMP_3104"),
messageParameters = params.errorClass match {
  case Some(_) => params.messageParameters
  case None => Map("message" -> params.message)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

How can it be set for non-SparkThrowable like here NumberFormatException?

Copy link
Contributor

@heyihong heyihong Dec 29, 2023

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

got it. will do.

params.message,
params.errorClass,
params.messageParameters)),
errorClass = "_LEGACY_ERROR_TEMP_3107",
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

errorClass = Some("DUPLICATE_KEY"),
messageParameters = Map("keyColumn" -> "`abc`"),
queryContext = Array.empty)
val error = constructor(testParams)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to update the test to cover both errorClass = Some(...) and errorClass = None

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@MaxGekk
Copy link
Member Author

MaxGekk commented Dec 30, 2023

Merging to master. Thank you, @heyihong and @dongjoon-hyun for review.

@MaxGekk MaxGekk closed this in b05c612 Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants