Sourabh Goyal created HIVE-25963:
------------------------------------

             Summary: Temporary table creation with not null constraint gets 
converted to external table 
                 Key: HIVE-25963
                 URL: https://issues.apache.org/jira/browse/HIVE-25963
             Project: Hive
          Issue Type: Bug
          Components: HiveServer2, Standalone Metastore
            Reporter: Sourabh Goyal
            Assignee: Sourabh Goyal


When creating a temporary table with not null, constraint it gets covered to 
external table. For example: 
create temporary table t2 (a int not null);
table t2' metadata looks like: 
{code:java}
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
|           col_name            |                     data_type                 
     |                      comment                       |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| a                             | int                                           
     |                                                    |
|                               | NULL                                          
     | NULL                                               |
| # Detailed Table Information  | NULL                                          
     | NULL                                               |
| Database:                     | default                                       
     | NULL                                               |
| OwnerType:                    | USER                                          
     | NULL                                               |
| Owner:                        | sourabh                                       
     | NULL                                               |
| CreateTime:                   | Tue Feb 15 15:20:13 PST 2022                  
     | NULL                                               |
| LastAccessTime:               | UNKNOWN                                       
     | NULL                                               |
| Retention:                    | 0                                             
     | NULL                                               |
| Location:                     | 
hdfs://localhost:9000/tmp/hive/sourabh/80d374a8-cd7a-4fcf-ae72-51b04ff9c3d8/_tmp_space.db/4574446d-c144-48f9-b4b6-2e9ee0ce5be4
 | NULL                                               |
| Table Type:                   | EXTERNAL_TABLE                                
     | NULL                                               |
| Table Parameters:             | NULL                                          
     | NULL                                               |
|                               | COLUMN_STATS_ACCURATE                         
     | {\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"a\":\"true\"}} |
|                               | EXTERNAL                                      
     | TRUE                                               |
|                               | TRANSLATED_TO_EXTERNAL                        
     | TRUE                                               |
|                               | bucketing_version                             
     | 2                                                  |
|                               | external.table.purge                          
     | TRUE                                               |
|                               | numFiles                                      
     | 0                                                  |
|                               | numRows                                       
     | 0                                                  |
|                               | rawDataSize                                   
     | 0                                                  |
|                               | totalSize                                     
     | 0                                                  |
|                               | transient_lastDdlTime                         
     | 1644967213                                         |
|                               | NULL                                          
     | NULL                                               |
| # Storage Information         | NULL                                          
     | NULL                                               |
| SerDe Library:                | 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe | NULL                       
                        |
| InputFormat:                  | org.apache.hadoop.mapred.TextInputFormat      
     | NULL                                               |
| OutputFormat:                 | 
org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat | NULL               
                                |
| Compressed:                   | No                                            
     | NULL                                               |
| Num Buckets:                  | -1                                            
     | NULL                                               |
| Bucket Columns:               | []                                            
     | NULL                                               |
| Sort Columns:                 | []                                            
     | NULL                                               |
| Storage Desc Params:          | NULL                                          
     | NULL                                               |
|                               | serialization.format                          
     | 1                                                  |
|                               | NULL                                          
     | NULL                                               |
| # Constraints                 | NULL                                          
     | NULL                                               |
|                               | NULL                                          
     | NULL                                               |
| # Not Null Constraints        | NULL                                          
     | NULL                                               |
| Table:                        | default.t2                                    
     | NULL                                               |
| Constraint Name:              | nn_157620106_1644967213860_0                  
     | NULL                                               |
| Column Name:                  | a                                             
     | NULL                                               |
|                               | NULL                                          
     | NULL                                               |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
 {code}
However if a temporary table is created *without,* not null constraint, it 
works as expected. For example: 
create temporary table t5 (a int);
 
{code:java}
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
|           col_name            |                     data_type                 
     |                      comment                       |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| a                             | int                                           
     |                                                    |
|                               | NULL                                          
     | NULL                                               |
| # Detailed Table Information  | NULL                                          
     | NULL                                               |
| Database:                     | default                                       
     | NULL                                               |
| OwnerType:                    | USER                                          
     | NULL                                               |
| Owner:                        | sourabh                                       
     | NULL                                               |
| CreateTime:                   | Tue Feb 15 15:34:44 PST 2022                  
     | NULL                                               |
| LastAccessTime:               | UNKNOWN                                       
     | NULL                                               |
| Retention:                    | 0                                             
     | NULL                                               |
| Location:                     | 
hdfs://localhost:9000/tmp/hive/sourabh/22fcb5c1-b9a6-4d51-8efc-86d7c167a242/_tmp_space.db/0515167f-ca1a-4c53-a1de-e4385fc96079
 | NULL                                               |
| Table Type:                   | MANAGED_TABLE                                 
     | NULL                                               |
| Table Parameters:             | NULL                                          
     | NULL                                               |
|                               | COLUMN_STATS_ACCURATE                         
     | {\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"a\":\"true\"}} |
|                               | bucketing_version                             
     | 2                                                  |
|                               | numFiles                                      
     | 0                                                  |
|                               | numRows                                       
     | 0                                                  |
|                               | rawDataSize                                   
     | 0                                                  |
|                               | totalSize                                     
     | 0                                                  |
|                               | NULL                                          
     | NULL                                               |
| # Storage Information         | NULL                                          
     | NULL                                               |
| SerDe Library:                | 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe | NULL                       
                        |
| InputFormat:                  | org.apache.hadoop.mapred.TextInputFormat      
     | NULL                                               |
| OutputFormat:                 | 
org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat | NULL               
                                |
| Compressed:                   | No                                            
     | NULL                                               |
| Num Buckets:                  | -1                                            
     | NULL                                               |
| Bucket Columns:               | []                                            
     | NULL                                               |
| Sort Columns:                 | []                                            
     | NULL                                               |
| Storage Desc Params:          | NULL                                          
     | NULL                                               |
|                               | serialization.format                          
     | 1                                                  |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
 

{code}
Temporary tables are managed tables as HS2 keeps them in memory. Their metadata 
is not persisted in HMS.

But  the above temp table t2 got converted into external table metadata for 
which gets persisted into HMS which is not the desired behavior.

 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to