Skip to content

Conversation

@imback82
Copy link
Contributor

@imback82 imback82 commented Jan 11, 2022

What changes were proposed in this pull request?

#35113 introduced HiveExternalCatalog.withClientWrappingException to to wrap a Hive exception to a Spark exception. However, there was a limitation of testing it against different Hive versions as outlined in #35173 (comment). This PR proposes to revert HiveExternalCatalog.withClientWrappingException and move wrapping logic to HiveClientImpl.

Why are the changes needed?

  1. To make testing against different Hive versions better.
  2. For Hive 0.12, the wrapping logic was not working correctly for dropDatabase because the message was not matching.

Does this PR introduce any user-facing change?

Yes, for Hive 0.12, the exception message will now be consistent with other versions.
Before:
InvalidOperationException(message:Database db is not empty)
After:
Cannot drop a non-empty database: db. Use CASCADE option to drop a non-empty database

How was this patch tested?

Added a new test coverage.

@github-actions github-actions bot added the SQL label Jan 11, 2022
client.dropDatabase(db, ignoreIfNotExists, cascade)
} { exception =>
if (exception.getClass.getName.equals("org.apache.hadoop.hive.ql.metadata.HiveException")
&& exception.getMessage.contains(s"Database $db is not empty")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cloud-fan Note that I removed . when checking the message.
For Hive 0.12, the exception message is InvalidOperationException(message:Database temporary is not empty), whereas for Hive >0.12, the message is [InvalidOperationException(message:Database temporary is not empty. One or more tables exist.)]. So the wrapping wasn't working for Hive 0.12.

@imback82 imback82 changed the title [SPARK-37636][SQL][FOLLOW-UP] Migrate HiveExternalCatalog.dropDatabase to use HiveExternalCatalog.withClientWrappingException [SPARK-37636][SQL][FOLLOW-UP] Move handling Hive exceptions for create/drop database to HiveClientImpl Jan 17, 2022
case Some(wrapped) => throw wrapped
case None => throw new AnalysisException(
e.getClass.getCanonicalName + ": " + e.getMessage, cause = Some(e))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is reverting changes made in #35113.

shim.createDatabase(client, hiveDb, ignoreIfExists)
} catch {
case _: AlreadyExistsException =>
throw new DatabaseAlreadyExistsException(database.name)
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 wondering if we need to do something similar as:

try {
shim.createPartitions(client, db, table, parts, ignoreIfExists)
} catch {
case e: InvocationTargetException => replaceExistException(e.getCause)
case e: Throwable => replaceExistException(e)
}

@MaxGekk do you happen to know?

shim.dropDatabase(client, name, true, ignoreIfNotExists, cascade)
} catch {
case e: HiveException if e.getMessage.contains(s"Database $name is not empty") =>
throw QueryCompilationErrors.cannotDropNonemptyDatabaseError(name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto

@imback82
Copy link
Contributor Author

@cloud-fan is this ready to be merged?

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in a4e2bf9 Jan 26, 2022
senthh pushed a commit to senthh/spark-1 that referenced this pull request Feb 3, 2022
…e/drop database to HiveClientImpl

### What changes were proposed in this pull request?

apache#35113 introduced `HiveExternalCatalog.withClientWrappingException` to to wrap a Hive exception to a Spark exception. However, there was a limitation of testing it against different Hive versions as outlined in  apache#35173 (comment). This PR proposes to revert `HiveExternalCatalog.withClientWrappingException` and move wrapping logic to `HiveClientImpl`.

### Why are the changes needed?

1. To make testing against different Hive versions better.
2. For Hive 0.12, the wrapping logic was not working correctly for `dropDatabase` because the message was not matching.

### Does this PR introduce _any_ user-facing change?

Yes, for Hive 0.12, the exception message will now be consistent with other versions.
Before:
`InvalidOperationException(message:Database db is not empty)`
After:
`Cannot drop a non-empty database: db. Use CASCADE option to drop a non-empty database`

### How was this patch tested?

Added a new test coverage.

Closes apache#35173 from imback82/drop_db_withClientWrappingException.

Authored-by: Terry Kim <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
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.

2 participants