You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ng...@apache.org on 2021/12/17 20:31:28 UTC

[hive] branch master updated: HIVE-25724: Support external tables only for special databases (Saihemanth Gantasala via Naveen Gangam)

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 8ca396a  HIVE-25724: Support external tables only for special databases (Saihemanth Gantasala via Naveen Gangam)
8ca396a is described below

commit 8ca396abf3de1c9905917efcdfaa22c65537b07d
Author: saihemanth <sa...@cloudera.com>
AuthorDate: Thu Nov 18 21:54:09 2021 -0800

    HIVE-25724: Support external tables only for special databases (Saihemanth Gantasala via Naveen Gangam)
---
 .../create_acid_table_with_special_db_property.q        | 11 +++++++++++
 .../create_acid_table_with_special_db_property.q.out    | 17 +++++++++++++++++
 .../hive/metastore/MetastoreDefaultTransformer.java     |  8 ++++++++
 3 files changed, 36 insertions(+)

diff --git a/ql/src/test/queries/clientnegative/create_acid_table_with_special_db_property.q b/ql/src/test/queries/clientnegative/create_acid_table_with_special_db_property.q
new file mode 100644
index 0000000..7fd79bd
--- /dev/null
+++ b/ql/src/test/queries/clientnegative/create_acid_table_with_special_db_property.q
@@ -0,0 +1,11 @@
+-- Acid table creation is not allowed when EXTERNAL_TABLES_ONLY property is set on database.
+set hive.mapred.mode=nonstrict;
+set hive.support.concurrency=true;
+set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+set hive.acid.direct.insert.enabled=false;
+set metastore.metadata.transformer.class=org.apache.hadoop.hive.metastore.MetastoreDefaultTransformer;
+
+create database repl_db_test with DBPROPERTIES('EXTERNAL_TABLES_ONLY'='true');
+use repl_db_test;
+
+CREATE TRANSACTIONAL TABLE transactional_table_test(key string, value string);
\ No newline at end of file
diff --git a/ql/src/test/results/clientnegative/create_acid_table_with_special_db_property.q.out b/ql/src/test/results/clientnegative/create_acid_table_with_special_db_property.q.out
new file mode 100644
index 0000000..d665610
--- /dev/null
+++ b/ql/src/test/results/clientnegative/create_acid_table_with_special_db_property.q.out
@@ -0,0 +1,17 @@
+PREHOOK: query: create database repl_db_test with DBPROPERTIES('EXTERNAL_TABLES_ONLY'='true')
+PREHOOK: type: CREATEDATABASE
+PREHOOK: Output: database:repl_db_test
+POSTHOOK: query: create database repl_db_test with DBPROPERTIES('EXTERNAL_TABLES_ONLY'='true')
+POSTHOOK: type: CREATEDATABASE
+POSTHOOK: Output: database:repl_db_test
+PREHOOK: query: use repl_db_test
+PREHOOK: type: SWITCHDATABASE
+PREHOOK: Input: database:repl_db_test
+POSTHOOK: query: use repl_db_test
+POSTHOOK: type: SWITCHDATABASE
+POSTHOOK: Input: database:repl_db_test
+PREHOOK: query: CREATE TRANSACTIONAL TABLE transactional_table_test(key string, value string)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:repl_db_test
+PREHOOK: Output: repl_db_test@transactional_table_test
+FAILED: Execution Error, return code 40000 from org.apache.hadoop.hive.ql.ddl.DDLTask. MetaException(message:Creation of ACID table is not allowed when the property 'EXTERNAL_TABLES_ONLY'='TRUE' is set on the database.)
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDefaultTransformer.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDefaultTransformer.java
index 25867c4..80847cc 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDefaultTransformer.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDefaultTransformer.java
@@ -70,6 +70,7 @@ public class MetastoreDefaultTransformer implements IMetaStoreMetadataTransforme
   private static final String OBJCAPABILITIES = "OBJCAPABILITIES".intern();
   private static final String MANAGERAWMETADATA = "MANAGE_RAW_METADATA".intern();
   private static final String ACCEPTSUNMODIFIEDMETADATA = "ACCEPTS_UNMODIFIED_METADATA".intern();
+  private static final String EXTERNALTABLESONLY = "EXTERNAL_TABLES_ONLY".intern();
 
   private static final List<String> ACIDCOMMONWRITELIST = new ArrayList(Arrays.asList(
       HIVEMANAGESTATS,
@@ -670,10 +671,17 @@ public class MetastoreDefaultTransformer implements IMetaStoreMetadataTransforme
           // should we check tbl directory existence?
         }
       } else { // ACID table
+        // if the property 'EXTERNAL_TABLES_ONLY'='true' is set on the database, then creating managed/ACID tables are prohibited. See HIVE-25724 for more details.
+        if (db.getParameters().containsKey(EXTERNALTABLESONLY) &&
+                db.getParameters().get(EXTERNALTABLESONLY).equalsIgnoreCase("true")) {
+          throw new MetaException("Creation of ACID table is not allowed when the property 'EXTERNAL_TABLES_ONLY'='TRUE' is set on the database.");
+        }
+
         if (processorCapabilities == null || processorCapabilities.isEmpty()) {
           throw new MetaException("Processor has no capabilities, cannot create an ACID table.");
         }
 
+
         newTable = validateTablePaths(table);
         if (isInsertAcid) { // MICRO_MANAGED Tables
           if (processorCapabilities.contains(HIVEMANAGEDINSERTWRITE)) {