You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2022/02/17 17:44:37 UTC

[GitHub] [hive] sourabh912 opened a new pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

sourabh912 opened a new pull request #3040:
URL: https://github.com/apache/hive/pull/3040


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   This PR fixes an issue in which a temporary table when created with not null column constraint, gets converted to external table.  It is because HMSClient api createTableWithConstraints() call createTable(createTableRequest) which is not overriden by SessionHiveMetaStoreClient (which handles temporary tables creation/fetch/deletion). As a result of which HMS client makes create_table() RPC call to HMS server which in turn changes the table to external table and also persists its metadata. This is not the desired behavior because temporary tables are stored in memory and the metadata for these should not persisted in HMS.   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   It fixes a bug as described in HIVE-25963
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducible example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   No
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   Enhanced the existing unit tests by adding positive cases. 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sourabh912 commented on pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
sourabh912 commented on pull request #3040:
URL: https://github.com/apache/hive/pull/3040#issuecomment-1057265718


   @yongzhi @harishjp @saihemanth-cloudera @hsnusonic  : Would appreciate feedback from you as well ! 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sourabh912 commented on a change in pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
sourabh912 commented on a change in pull request #3040:
URL: https://github.com/apache/hive/pull/3040#discussion_r818961752



##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -1247,31 +1247,11 @@ public void createTable(Table tbl) throws AlreadyExistsException,
 
   public void createTable(Table tbl, EnvironmentContext envContext) throws AlreadyExistsException,
       InvalidObjectException, MetaException, NoSuchObjectException, TException {
-    if (!tbl.isSetCatName()) {
-      tbl.setCatName(getDefaultCatalog(conf));
-    }
-    HiveMetaHook hook = getHook(tbl);
-    if (hook != null) {
-      hook.preCreateTable(tbl);
-    }
-    boolean success = false;
-    try {
-      // Subclasses can override this step (for example, for temporary tables)
-      create_table_with_environment_context(tbl, envContext);
-      if (hook != null) {
-        hook.commitCreateTable(tbl);
-      }
-      success = true;
-    }
-    finally {
-      if (!success && (hook != null)) {
-        try {
-          hook.rollbackCreateTable(tbl);
-        } catch (Exception e){
-          LOG.error("Create rollback failed with", e);
-        }
-      }
+    CreateTableRequest request = new CreateTableRequest(tbl);
+    if (envContext != null) {
+      request.setEnvContext(envContext);
     }
+    createTable(request);

Review comment:
       `createTable(request)` method at line number 1284 is taking care of that already.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sourabh912 commented on pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
sourabh912 commented on pull request #3040:
URL: https://github.com/apache/hive/pull/3040#issuecomment-1043233911


   @nrg4878 : Please review and provide your feedback.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sourabh912 commented on pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
sourabh912 commented on pull request #3040:
URL: https://github.com/apache/hive/pull/3040#issuecomment-1050149910


   The only test `stats_part_multi_insert_acid.q` failing in the latest commit seems unrelated to this patch because it is failing in other Hive patches too for example: http://ci.hive.apache.org/blue/organizations/jenkins/hive-precommit/detail/PR-3049/1/tests


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] nrg4878 commented on pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
nrg4878 commented on pull request #3040:
URL: https://github.com/apache/hive/pull/3040#issuecomment-1064532858


   Fix has been merged. Please close the PR and the jira as well.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] hsnusonic commented on a change in pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
hsnusonic commented on a change in pull request #3040:
URL: https://github.com/apache/hive/pull/3040#discussion_r813399086



##########
File path: ql/src/test/results/clientpositive/llap/enforce_constraint_notnull.q.out
##########
@@ -6411,53 +6364,16 @@ STAGE PLANS:
                     expressions: UDFToInteger(key) (type: int)
                     outputColumnNames: _col0
                     Statistics: Num rows: 500 Data size: 2000 Basic stats: COMPLETE Column stats: COMPLETE
-                    Filter Operator
-                      predicate: enforce_constraint(_col0 is not null) (type: boolean)

Review comment:
       Does this mean the not null constraint is not applied after the change?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sourabh912 commented on a change in pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
sourabh912 commented on a change in pull request #3040:
URL: https://github.com/apache/hive/pull/3040#discussion_r818958406



##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -1247,31 +1247,11 @@ public void createTable(Table tbl) throws AlreadyExistsException,
 
   public void createTable(Table tbl, EnvironmentContext envContext) throws AlreadyExistsException,
       InvalidObjectException, MetaException, NoSuchObjectException, TException {
-    if (!tbl.isSetCatName()) {
-      tbl.setCatName(getDefaultCatalog(conf));

Review comment:
       Good catch ! 
   I will add them back. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sourabh912 commented on a change in pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
sourabh912 commented on a change in pull request #3040:
URL: https://github.com/apache/hive/pull/3040#discussion_r814207394



##########
File path: ql/src/test/results/clientpositive/llap/enforce_constraint_notnull.q.out
##########
@@ -6411,53 +6364,16 @@ STAGE PLANS:
                     expressions: UDFToInteger(key) (type: int)
                     outputColumnNames: _col0
                     Statistics: Num rows: 500 Data size: 2000 Basic stats: COMPLETE Column stats: COMPLETE
-                    Filter Operator
-                      predicate: enforce_constraint(_col0 is not null) (type: boolean)

Review comment:
       Yes, it means that not null constraint does not have any meaning for temporary tables. Before this patch, a temp table with constraints was getting persisted in metastore and therefore had constraint information persisted. But  after this patch, constraints information will get lost for temporary tables unless we store constraints related info in memory. 
   
   @nrg4878 : Is the behavior for temporary table in terms on constraints as expected after this patch? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] saihemanth-cloudera commented on a change in pull request #3040: HIVE-25963: Create temporary table with not null constraint gets converted to external table

Posted by GitBox <gi...@apache.org>.
saihemanth-cloudera commented on a change in pull request #3040:
URL: https://github.com/apache/hive/pull/3040#discussion_r818520185



##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -1247,31 +1247,11 @@ public void createTable(Table tbl) throws AlreadyExistsException,
 
   public void createTable(Table tbl, EnvironmentContext envContext) throws AlreadyExistsException,
       InvalidObjectException, MetaException, NoSuchObjectException, TException {
-    if (!tbl.isSetCatName()) {
-      tbl.setCatName(getDefaultCatalog(conf));

Review comment:
       catalog name needs to be set if it is not set. Can you please add these lines back? 

##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -1247,31 +1247,11 @@ public void createTable(Table tbl) throws AlreadyExistsException,
 
   public void createTable(Table tbl, EnvironmentContext envContext) throws AlreadyExistsException,
       InvalidObjectException, MetaException, NoSuchObjectException, TException {
-    if (!tbl.isSetCatName()) {
-      tbl.setCatName(getDefaultCatalog(conf));
-    }
-    HiveMetaHook hook = getHook(tbl);
-    if (hook != null) {
-      hook.preCreateTable(tbl);
-    }
-    boolean success = false;
-    try {
-      // Subclasses can override this step (for example, for temporary tables)
-      create_table_with_environment_context(tbl, envContext);
-      if (hook != null) {
-        hook.commitCreateTable(tbl);
-      }
-      success = true;
-    }
-    finally {
-      if (!success && (hook != null)) {
-        try {
-          hook.rollbackCreateTable(tbl);
-        } catch (Exception e){
-          LOG.error("Create rollback failed with", e);
-        }
-      }
+    CreateTableRequest request = new CreateTableRequest(tbl);
+    if (envContext != null) {
+      request.setEnvContext(envContext);
     }
+    createTable(request);

Review comment:
       Can you please add L4448-4451 to the CreateTableRequest object here before calling the CreateTable() api? We would need to send the processor capabilities (if available) to HMS.

##########
File path: ql/src/test/results/clientpositive/llap/enforce_constraint_notnull.q.out
##########
@@ -6411,53 +6364,16 @@ STAGE PLANS:
                     expressions: UDFToInteger(key) (type: int)
                     outputColumnNames: _col0
                     Statistics: Num rows: 500 Data size: 2000 Basic stats: COMPLETE Column stats: COMPLETE
-                    Filter Operator
-                      predicate: enforce_constraint(_col0 is not null) (type: boolean)

Review comment:
       I think this is the right behavior. Constraints on temp tables will not be persisted in metastore and hence the explain plan shouldn't show stats e.t.c.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org