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

HIVE-27565: Fix NPE when dropping table in HiveQueryLifeTimeHook::checkAndRollbackCTAS #4549

Merged
merged 3 commits into from Aug 7, 2023

Conversation

zhangbutao
Copy link
Contributor

What changes were proposed in this pull request?

Why are the changes needed?

In the case of HIVE-27565, tblPath maybe null, we can skip this if tblPath is null.

FileSystem fs = tblPath.getFileSystem(conf);

Does this PR introduce any user-facing change?

No

Is the change a dependency upgrade?

How was this patch tested?

return;
}
} catch (Exception e) {
throw new RuntimeException("Not able to check whether the CTAS table directory exists due to: ", 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.

I am not sure if the error message is reasonable, as some failed queries may not be CTAS type. Welcome to come up with comment here.

Copy link
Member

@ayushtkn ayushtkn Aug 4, 2023

Choose a reason for hiding this comment

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

The method calling is private void checkAndRollbackCTAS(QueryLifeTimeHookContext ctx) { and you mean to say this method gets invoked for non CTAS queries as well? If so just remove CTAS from the exception message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean to say this method gets invoked for non CTAS queries as well?

Yse, In my case HIVE-27565 which is Drop type , also invoked checkAndRollbackCTAS(QueryLifeTimeHookContext ctx). But i think this method is only for handling CTAS type queries, so other queries should return early to leave the method.

I will refine the PR to return early if the query is not CTAS.

Copy link
Member

@ayushtkn ayushtkn left a comment

Choose a reason for hiding this comment

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

looks fair enough, can you extend a test as well?

@zhangbutao
Copy link
Contributor Author

looks fair enough, can you extend a test as well?

@ayushtkn It seems not easy to add the test as i only get the short error message instead of the complete error stacktrace in the qltest output, and the short error message can not display HiveQueryLifeTimeHook error info.

I think it is a simple fix, maybe no need to add test? :)
@SourabhBadhya Could you also take a look? As you are the original writer about HiveQueryLifeTimeHook. Thanks.

Copy link
Contributor

@SourabhBadhya SourabhBadhya left a comment

Choose a reason for hiding this comment

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

Minor implementation details. Otherwise looks good.

@@ -71,20 +71,23 @@ private void checkAndRollbackCTAS(QueryLifeTimeHookContext ctx) {
QueryPlan queryPlan = ctx.getHookContext().getQueryPlan();
boolean isCTAS = Optional.ofNullable(queryPlan.getQueryProperties())
.map(queryProps -> queryProps.isCTAS()).orElse(false);
// return early if the query is not CATS type.
if (!isCTAS)
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think we must add this since the check is already done below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


if (isCTAS && tblPath != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include this. The idea is to clean up any directories which are created by CTAS but are not committed. Hence cleanup must be scheduled only when there is a directory and the query is a CTAS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

FileSystem fs = tblPath.getFileSystem(conf);
if (!fs.exists(tblPath)) {
return;
if (tblPath != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel its better to include entire logic below -

if (isCTAS && tblPath != null) {
     try {
        FileSystem fs = tblPath.getFileSystem(conf);
        if (!fs.exists(tblPath)) {
          return;
        }
      } catch (Exception e) {
        throw new RuntimeException("Not able to check whether the CTAS table directory exists due to: ", e);
      }
      // Remaining logic
      ....
 }

The CTAS check and the non-nullability of the path will be checked then in a single if clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. Thanks.

@sonarcloud
Copy link

sonarcloud bot commented Aug 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

warning The version of Java (11.0.8) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

Copy link
Member

@ayushtkn ayushtkn left a comment

Choose a reason for hiding this comment

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

LGTM.
@SourabhBadhya can you check again, if your comments are addressed?

Copy link
Contributor

@SourabhBadhya SourabhBadhya left a comment

Choose a reason for hiding this comment

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

LGTM +1

@ayushtkn ayushtkn merged commit a901668 into apache:master Aug 7, 2023
5 checks passed
tarak271 pushed a commit to tarak271/hive-1 that referenced this pull request Dec 19, 2023
…ckAndRollbackCTAS (apache#4549). (zhangbutao,  reviewed by Ayush Saxena, Sourabh Badhya)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants