This is an automated email from the ASF dual-hosted git repository.
ngangam pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 7a5ec91 HIVE-25963: Create temporary table with not null constraint
gets converted to external table(Sourabh Goyal via Yu-Wen Lai and Naveen Gangam)
7a5ec91 is described below
commit 7a5ec913db6ca294a2753a21f6b14e78006287cc
Author: Sourabh Goyal <[email protected]>
AuthorDate: Wed Feb 16 15:51:23 2022 -0800
HIVE-25963: Create temporary table with not null constraint gets converted
to external table(Sourabh Goyal via Yu-Wen Lai and Naveen Gangam)
Change-Id: I05e6d1e2504d3695c8cfea8c87c6f4ed5dfc92e0
---
.../ql/metadata/SessionHiveMetaStoreClient.java | 24 +++++------
.../clientpositive/show_create_table_temp_table.q | 4 ++
.../llap/show_create_table_temp_table.q.out | 34 ++++++++++++++++
.../hadoop/hive/metastore/HiveMetaStoreClient.java | 47 ++++------------------
4 files changed, 55 insertions(+), 54 deletions(-)
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java
b/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java
index 31f8209..75d3609 100644
---
a/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java
+++
b/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java
@@ -59,6 +59,7 @@ import org.apache.hadoop.hive.metastore.api.ColumnStatistics;
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc;
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
import org.apache.hadoop.hive.metastore.api.ConfigValSecurityException;
+import org.apache.hadoop.hive.metastore.api.CreateTableRequest;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.EnvironmentContext;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
@@ -162,22 +163,15 @@ public class SessionHiveMetaStoreClient extends
HiveMetaStoreClientWithLocalCach
return wh;
}
- // TODO CAT - a number of these need to be updated. Don't bother with
deprecated methods as
- // this is just an internal class. Wait until we're ready to move all the
catalog stuff up
- // into ql.
-
@Override
- protected void create_table_with_environment_context(
- org.apache.hadoop.hive.metastore.api.Table tbl, EnvironmentContext
envContext)
- throws AlreadyExistsException, InvalidObjectException,
- MetaException, NoSuchObjectException, TException {
-
+ protected void create_table(CreateTableRequest request) throws
+ InvalidObjectException, MetaException, NoSuchObjectException, TException
{
+ org.apache.hadoop.hive.metastore.api.Table tbl = request.getTable();
if (tbl.isTemporary()) {
- createTempTable(tbl, envContext);
+ createTempTable(tbl);
return;
}
- // non-temp tables should use underlying client.
- super.create_table_with_environment_context(tbl, envContext);
+ super.create_table(request);
}
@Override
@@ -594,9 +588,9 @@ public class SessionHiveMetaStoreClient extends
HiveMetaStoreClientWithLocalCach
return super.deleteTableColumnStatistics(dbName, tableName, colName,
engine);
}
- private void createTempTable(org.apache.hadoop.hive.metastore.api.Table tbl,
- EnvironmentContext envContext) throws AlreadyExistsException,
InvalidObjectException,
- MetaException, NoSuchObjectException, TException {
+ private void createTempTable(org.apache.hadoop.hive.metastore.api.Table tbl)
throws
+ AlreadyExistsException, InvalidObjectException, MetaException,
NoSuchObjectException,
+ TException {
boolean isVirtualTable =
tbl.getTableName().startsWith(SemanticAnalyzer.VALUES_TMP_TABLE_NAME_PREFIX);
diff --git a/ql/src/test/queries/clientpositive/show_create_table_temp_table.q
b/ql/src/test/queries/clientpositive/show_create_table_temp_table.q
index 19c2c3e..c595d06 100644
--- a/ql/src/test/queries/clientpositive/show_create_table_temp_table.q
+++ b/ql/src/test/queries/clientpositive/show_create_table_temp_table.q
@@ -3,4 +3,8 @@ create database tmpdb;
create temporary table tmpdb.tmp1 (c1 string, c2 string);
show create table tmpdb.tmp1;
drop table tmp1;
+create temporary table tmpdb.tmp_not_null_tbl (a int NOT NULL);
+show create table tmpdb.tmp_not_null_tbl;
+drop table tmpdb.tmp_not_null_tbl;
+
drop database tmpdb;
diff --git
a/ql/src/test/results/clientpositive/llap/show_create_table_temp_table.q.out
b/ql/src/test/results/clientpositive/llap/show_create_table_temp_table.q.out
index 917dca5..6194d14 100644
--- a/ql/src/test/results/clientpositive/llap/show_create_table_temp_table.q.out
+++ b/ql/src/test/results/clientpositive/llap/show_create_table_temp_table.q.out
@@ -35,6 +35,40 @@ PREHOOK: query: drop table tmp1
PREHOOK: type: DROPTABLE
POSTHOOK: query: drop table tmp1
POSTHOOK: type: DROPTABLE
+PREHOOK: query: create temporary table tmpdb.tmp_not_null_tbl (a int NOT NULL)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:tmpdb
+PREHOOK: Output: tmpdb@tmp_not_null_tbl
+POSTHOOK: query: create temporary table tmpdb.tmp_not_null_tbl (a int NOT NULL)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:tmpdb
+POSTHOOK: Output: tmpdb@tmp_not_null_tbl
+PREHOOK: query: show create table tmpdb.tmp_not_null_tbl
+PREHOOK: type: SHOW_CREATETABLE
+PREHOOK: Input: tmpdb@tmp_not_null_tbl
+POSTHOOK: query: show create table tmpdb.tmp_not_null_tbl
+POSTHOOK: type: SHOW_CREATETABLE
+POSTHOOK: Input: tmpdb@tmp_not_null_tbl
+CREATE TEMPORARY TABLE `tmpdb`.`tmp_not_null_tbl`(
+ `a` int)
+ROW FORMAT SERDE
+ 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
+STORED AS INPUTFORMAT
+ 'org.apache.hadoop.mapred.TextInputFormat'
+OUTPUTFORMAT
+ 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
+LOCATION
+#### A masked pattern was here ####
+TBLPROPERTIES (
+ 'bucketing_version'='2')
+PREHOOK: query: drop table tmpdb.tmp_not_null_tbl
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: tmpdb@tmp_not_null_tbl
+PREHOOK: Output: tmpdb@tmp_not_null_tbl
+POSTHOOK: query: drop table tmpdb.tmp_not_null_tbl
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: tmpdb@tmp_not_null_tbl
+POSTHOOK: Output: tmpdb@tmp_not_null_tbl
PREHOOK: query: drop database tmpdb
PREHOOK: type: DROPDATABASE
PREHOOK: Input: database:tmpdb
diff --git
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
index e9c5351..920b198 100644
---
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
+++
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
@@ -1246,31 +1246,11 @@ public class HiveMetaStoreClient implements
IMetaStoreClient, AutoCloseable {
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);
}
/**
@@ -1299,7 +1279,7 @@ public class HiveMetaStoreClient implements
IMetaStoreClient, AutoCloseable {
boolean success = false;
try {
// Subclasses can override this step (for example, for temporary tables)
- client.create_table_req(request);
+ create_table(request);
if (hook != null) {
hook.commitCreateTable(tbl);
}
@@ -4353,21 +4333,10 @@ public class HiveMetaStoreClient implements
IMetaStoreClient, AutoCloseable {
return client.get_all_functions();
}
- protected void create_table_with_environment_context(Table tbl,
EnvironmentContext envContext)
- throws AlreadyExistsException, InvalidObjectException,
- MetaException, NoSuchObjectException, TException {
- CreateTableRequest request = new CreateTableRequest(tbl);
- if (envContext != null) {
- request.setEnvContext(envContext);
- }
-
- if (processorCapabilities != null) {
- request.setProcessorCapabilities(new
ArrayList<String>(Arrays.asList(processorCapabilities)));
- request.setProcessorIdentifier(processorIdentifier);
- }
-
+ protected void create_table(CreateTableRequest request) throws
+ InvalidObjectException, MetaException, NoSuchObjectException, TException
{
client.create_table_req(request);
-}
+ }
protected void drop_table_with_environment_context(String catName, String
dbname, String name,
boolean deleteData, EnvironmentContext envContext) throws TException {