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

[SPARK-48585][SQL] Make built-in JdbcDialect's method classifyException throw out the original exception #46937

Closed
wants to merge 10 commits into from

Conversation

panbingkun
Copy link
Contributor

@panbingkun panbingkun commented Jun 11, 2024

What changes were proposed in this pull request?

The pr aims to make built-in JdbcDialect's method classifyException throw out the original exception.

Why are the changes needed?

As discussed in #46912 (comment), the following code:

def classifyException(
e: Throwable,
errorClass: String,
messageParameters: Map[String, String],
description: String): AnalysisException = {
classifyException(description, e)

have lost the original cause of the error, let's correct it.

Does this PR introduce any user-facing change?

Yes, more accurate error conditions for end users.

How was this patch tested?

  • Manually test.
  • Update existed UT & Pass GA.

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

No.

@github-actions github-actions bot added the SQL label Jun 11, 2024
@panbingkun panbingkun changed the title [Only Test] test first [SPARK-48585][SQL] Make JdbcDialect.classifyException throw out the original exception Jun 11, 2024
* @return `AnalysisException` or its sub-class.
*/
def classifyException(
e: Throwable,
errorClass: String,
messageParameters: Map[String, String],
description: String): AnalysisException = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the code logic, it seems that there is no need for the field description to exist. Let's remove it.
Although JdbcDialect is marked as DeveloperApi, this method has been added from Spark version 4.0 and the version 4.0 has not been released yet.
Can we directly remove it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there was a reason to call the legacy classifyException method here. Can we dig into it?

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 investigating history.

Copy link
Member

Choose a reason for hiding this comment

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

This guarantees pre-implemented legacy classifyExceptions from third-party to be correctly called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's right, see PR below:
1.#44358, the modification of this PR resulted in break changes, and with the suggestion of cloud-fan:
image
the following PR has been created.

2.#44449, this PR has restored compatibility behavior
image

@panbingkun
Copy link
Contributor Author

To reduce confusion among reviewers, this PR does not include the function of adding the prefix catalog info to ident discussed by https://github.com/apache/spark/pull/46912/files#r1630859747
It will be completed as a separate PR.

@panbingkun
Copy link
Contributor Author

cc @cloud-fan @yaooqinn

@panbingkun panbingkun marked this pull request as ready for review June 11, 2024 11:31
description: String): AnalysisException = {
classifyException(description, e)
messageParameters: Map[String, String]): AnalysisException = {
new AnalysisException(
Copy link
Contributor

Choose a reason for hiding this comment

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

AnalysisException seems unreasonable here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this should already be in the execution phase, so it's not reasonable.
Let me go through the history first.

@panbingkun
Copy link
Contributor Author

panbingkun commented Jun 12, 2024

  • The idea of this PR is to make various built-in JDBC dialects overload the method def classifyException(e: Throwable, errorClass: String, messageParameters: Map[String, String], description: String): AnalysisException and make them call final def classifyException(e: Throwable, errorClass: String, messageParameters: Map[String, String]): AnalysisException, so that the original exception can be thrown.

  • Another approach is to define a trait as follows:

trait JdbcDialectHelper extends JdbcDialect {
  
  override def classifyException(
      e: Throwable,
      errorClass: String,
      messageParameters: Map[String, String],
      description: String): AnalysisException = {
    new AnalysisException(
      errorClass = errorClass,
      messageParameters = messageParameters,
      cause = Some(e))
  }
}

eg:

private[sql] case class H2Dialect() extends JdbcDialect with `JdbcDialectHelper` {

}

and then have various built-in jdbc dialects with it, so that there is no need to make changes to each built-in jdbc dialects dialect, but this will add an extra trait.

WDYT @cloud-fan @yaooqinn @beliefer ?

@panbingkun panbingkun changed the title [SPARK-48585][SQL] Make JdbcDialect.classifyException throw out the original exception [SPARK-48585][SQL] Make built-in JdbcDialect's method classifyException throw out the original exception Jun 12, 2024
@panbingkun panbingkun changed the title [SPARK-48585][SQL] Make built-in JdbcDialect's method classifyException throw out the original exception [SPARK-48585][SQL] Make built-in JdbcDialect's method classifyException throw out the original exception Jun 12, 2024
@panbingkun
Copy link
Contributor Author

panbingkun commented Jun 13, 2024

  • Another approach is to define a trait as follows:
trait JdbcDialectHelper extends JdbcDialect {
  
  override def classifyException(
      e: Throwable,
      errorClass: String,
      messageParameters: Map[String, String],
      description: String): AnalysisException = {
    new AnalysisException(
      errorClass = errorClass,
      messageParameters = messageParameters,
      cause = Some(e))
  }
}

eg:

private[sql] case class H2Dialect() extends JdbcDialect with `JdbcDialectHelper` {

}

and then have various built-in jdbc dialects with it, so that there is no need to make changes to each built-in jdbc dialects dialect, but this will add an extra trait.

I have already used this

@panbingkun panbingkun requested a review from cloud-fan June 14, 2024 01:26
/**
* Make the `classifyException` method throw out the original exception
*/
trait JdbcDialectHelper extends JdbcDialect {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we give it a clearer name? like NoLegacyJDBCError.

Copy link
Contributor Author

@panbingkun panbingkun Jun 17, 2024

Choose a reason for hiding this comment

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

Okay, let me update it.
Done.

@LuciferYang
Copy link
Contributor

Merged into master for Spark 4.0. Thanks @panbingkun @cloud-fan @yaooqinn @beliefer

@panbingkun
Copy link
Contributor Author

Merged into master for Spark 4.0. Thanks @panbingkun @cloud-fan @yaooqinn @beliefer

Thanks all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants