You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/02/22 13:55:00 UTC

[jira] [Work logged] (HIVE-25826) Support table defaults at each database level

     [ https://issues.apache.org/jira/browse/HIVE-25826?focusedWorklogId=730918&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-730918 ]

ASF GitHub Bot logged work on HIVE-25826:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Feb/22 13:54
            Start Date: 22/Feb/22 13:54
    Worklog Time Spent: 10m 
      Work Description: nrg4878 commented on a change in pull request #2924:
URL: https://github.com/apache/hive/pull/2924#discussion_r792899403



##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestDatabaseTableDefault.java
##########
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.FileUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+//import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+/**
+ * This class resides in itests to facilitate running query using Tez engine, since the jars are
+ * fully loaded here, which is not the case if it stays in ql.
+ */
+public class TestDatabaseTableDefault {
+    static final private Logger LOG = LoggerFactory.getLogger(TestDatabaseTableDefault.class);
+
+    private HiveConf hiveConf;
+    private IDriver d;
+    private static final String database_with_default_table_type = "database_with_default_table_type";
+    private static final String default_db = "default_db";
+    private static final String table_type_managed = "MANAGED_TABLE";
+    private static final String table_type_external = "EXTERNAL_TABLE";
+    File ext_wh = null;
+    File wh = null;
+    protected static HiveMetaStoreClient client;
+    protected static Configuration conf;
+    private static enum TableNames {
+        TRANSACTIONALTBL1("transactional_table_1"),
+        TRANSACTIONALTBL2("transactional_table_2"),
+        TRANSACTIONALTBL3("transactional_table_3"),
+        TRANSACTIONALTBL4("transactional_table_4"),
+        TRANSACTIONALTBL5("transactional_table_5"),
+        TRANSACTIONALTBL6("transactional_table_6"),
+        TRANSACTIONALTBL7("transactional_table_7"),
+        EXTERNALTABLE1("external_table_1"),
+        EXTERNALTABLE2("external_table_2"),
+        EXTERNALTABLE3("external_table_3"),
+        EXTERNALTABLE4("external_table_4"),
+        EXTERNALTABLE5("external_table_5"),
+        EXTERNALTABLE6("external_table_6"),
+        NONACIDPART("nonAcidPart"),
+        NONACIDNONBUCKET("nonAcidNonBucket");
+
+        private final String name;
+        @Override
+        public String toString() {
+            return name;
+        }
+        TableNames(String name) {
+            this.name = name;
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        hiveConf = new HiveConf(this.getClass());
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_CREATE_TABLES_AS_INSERT_ONLY, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, true);
+        hiveConf.set(HiveConf.ConfVars.HIVEDEFAULTMANAGEDFILEFORMAT.varname, "ORC");
+        hiveConf.setVar(HiveConf.ConfVars.HIVE_TXN_MANAGER, DbTxnManager.class.getName());
+        hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_CAPABILITIES.varname, "HIVEFULLACIDREAD,HIVEFULLACIDWRITE,HIVECACHEINVALIDATE,HIVEMANAGESTATS,HIVEMANAGEDINSERTWRITE,HIVEMANAGEDINSERTREAD");
+        TestTxnDbUtil.setConfValues(hiveConf);
+        TestTxnDbUtil.prepDb(hiveConf);
+
+        SessionState.start(new SessionState(hiveConf));
+        d = DriverFactory.newDriver(hiveConf);
+
+        wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive" + File.separator);
+        wh.mkdirs();
+
+        ext_wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive-external" + File.separator);
+        ext_wh.mkdirs();
+
+        MetastoreConf.setVar(hiveConf, ConfVars.METASTORE_METADATA_TRANSFORMER_CLASS,
+                "org.apache.hadoop.hive.metastore.MetastoreDefaultTransformer");
+        MetastoreConf.setBoolVar(hiveConf, ConfVars.HIVE_IN_TEST, false);
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE, wh.getCanonicalPath());
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE_EXTERNAL, ext_wh.getCanonicalPath());
+        MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        client = new HiveMetaStoreClient(hiveConf);
+
+
+        dropTables();
+        runStatementOnDriver("create database " + database_with_default_table_type +" with DBPROPERTIES('defaultTableType'='EXTERNAL')");
+        runStatementOnDriver("create database " + default_db);
+    }
+
+    /**
+     * this is to test differety types of Acid tables
+     */
+    String getTblProperties() {
+        return "TBLPROPERTIES ('transactional'='true')";
+    }
+
+    private void dropTables() throws Exception {
+        for(TableNames t : TableNames.values()) {
+            runStatementOnDriver("drop table if exists " + t);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        try {
+            if (d != null) {
+                dropTables();
+                runStatementOnDriver("drop database if exists " + database_with_default_table_type +" cascade");
+                runStatementOnDriver("drop database if exists " + default_db + " cascade");
+                d.close();
+                d.destroy();
+                d = null;
+            }
+        } finally {
+            FileUtils.deleteDirectory(wh);
+            FileUtils.deleteDirectory(ext_wh);
+        }
+    }
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateManagedTablesInDBWithDefaultTableType_External method for creating managed tables in a special database.
+     * @throws Exception If there is an error creating managed tables
+     */
+    @Test
+    public void testCreateManagedTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.TRANSACTIONALTBL1 + " (id int, name string) " + getTblProperties());
+        Table managed_table_1 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_1.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create managed table " + TableNames.TRANSACTIONALTBL2 + " (id int, name string) ");
+        Table managed_table_2 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_2.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL3 + " (id int, name string) ");
+        Table managed_table_3 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_3.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL4 + " like " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_4 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL4.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_4.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL5 + " as select * from " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_5 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL5.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_5.getTableType(), table_type_managed);
+
+        LOG.info("Test execution complete:testCreateManagedTablesInDBWithDefaultTableType_External");
+    }
+
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateExternalTablesInDBWithDefaultTableType_External method for creating external tables in a special database.
+     * @throws Exception If there is an error creating external tables
+     */
+    @Test
+    public void testCreateExternalTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE1 + " (id int, name string)");
+        Table external_table_1 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_1.getTableType(), table_type_external);
+
+        runStatementOnDriver("create external table " + TableNames.EXTERNALTABLE2 + " (id int, name string) ");
+        Table external_table_2 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_2.getTableType(), table_type_external);

Review comment:
       ditto

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestDatabaseTableDefault.java
##########
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.FileUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+//import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+/**
+ * This class resides in itests to facilitate running query using Tez engine, since the jars are
+ * fully loaded here, which is not the case if it stays in ql.
+ */
+public class TestDatabaseTableDefault {
+    static final private Logger LOG = LoggerFactory.getLogger(TestDatabaseTableDefault.class);
+
+    private HiveConf hiveConf;
+    private IDriver d;
+    private static final String database_with_default_table_type = "database_with_default_table_type";
+    private static final String default_db = "default_db";
+    private static final String table_type_managed = "MANAGED_TABLE";
+    private static final String table_type_external = "EXTERNAL_TABLE";
+    File ext_wh = null;
+    File wh = null;
+    protected static HiveMetaStoreClient client;
+    protected static Configuration conf;
+    private static enum TableNames {
+        TRANSACTIONALTBL1("transactional_table_1"),
+        TRANSACTIONALTBL2("transactional_table_2"),
+        TRANSACTIONALTBL3("transactional_table_3"),
+        TRANSACTIONALTBL4("transactional_table_4"),
+        TRANSACTIONALTBL5("transactional_table_5"),
+        TRANSACTIONALTBL6("transactional_table_6"),
+        TRANSACTIONALTBL7("transactional_table_7"),
+        EXTERNALTABLE1("external_table_1"),
+        EXTERNALTABLE2("external_table_2"),
+        EXTERNALTABLE3("external_table_3"),
+        EXTERNALTABLE4("external_table_4"),
+        EXTERNALTABLE5("external_table_5"),
+        EXTERNALTABLE6("external_table_6"),
+        NONACIDPART("nonAcidPart"),
+        NONACIDNONBUCKET("nonAcidNonBucket");
+
+        private final String name;
+        @Override
+        public String toString() {
+            return name;
+        }
+        TableNames(String name) {
+            this.name = name;
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        hiveConf = new HiveConf(this.getClass());
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_CREATE_TABLES_AS_INSERT_ONLY, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, true);
+        hiveConf.set(HiveConf.ConfVars.HIVEDEFAULTMANAGEDFILEFORMAT.varname, "ORC");
+        hiveConf.setVar(HiveConf.ConfVars.HIVE_TXN_MANAGER, DbTxnManager.class.getName());
+        hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_CAPABILITIES.varname, "HIVEFULLACIDREAD,HIVEFULLACIDWRITE,HIVECACHEINVALIDATE,HIVEMANAGESTATS,HIVEMANAGEDINSERTWRITE,HIVEMANAGEDINSERTREAD");
+        TestTxnDbUtil.setConfValues(hiveConf);
+        TestTxnDbUtil.prepDb(hiveConf);
+
+        SessionState.start(new SessionState(hiveConf));
+        d = DriverFactory.newDriver(hiveConf);
+
+        wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive" + File.separator);
+        wh.mkdirs();
+
+        ext_wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive-external" + File.separator);
+        ext_wh.mkdirs();
+
+        MetastoreConf.setVar(hiveConf, ConfVars.METASTORE_METADATA_TRANSFORMER_CLASS,
+                "org.apache.hadoop.hive.metastore.MetastoreDefaultTransformer");
+        MetastoreConf.setBoolVar(hiveConf, ConfVars.HIVE_IN_TEST, false);
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE, wh.getCanonicalPath());
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE_EXTERNAL, ext_wh.getCanonicalPath());
+        MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        client = new HiveMetaStoreClient(hiveConf);
+
+
+        dropTables();
+        runStatementOnDriver("create database " + database_with_default_table_type +" with DBPROPERTIES('defaultTableType'='EXTERNAL')");
+        runStatementOnDriver("create database " + default_db);
+    }
+
+    /**
+     * this is to test differety types of Acid tables
+     */
+    String getTblProperties() {
+        return "TBLPROPERTIES ('transactional'='true')";
+    }
+
+    private void dropTables() throws Exception {
+        for(TableNames t : TableNames.values()) {
+            runStatementOnDriver("drop table if exists " + t);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        try {
+            if (d != null) {
+                dropTables();
+                runStatementOnDriver("drop database if exists " + database_with_default_table_type +" cascade");
+                runStatementOnDriver("drop database if exists " + default_db + " cascade");
+                d.close();
+                d.destroy();
+                d = null;
+            }
+        } finally {
+            FileUtils.deleteDirectory(wh);
+            FileUtils.deleteDirectory(ext_wh);
+        }
+    }
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateManagedTablesInDBWithDefaultTableType_External method for creating managed tables in a special database.
+     * @throws Exception If there is an error creating managed tables
+     */
+    @Test
+    public void testCreateManagedTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.TRANSACTIONALTBL1 + " (id int, name string) " + getTblProperties());
+        Table managed_table_1 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_1.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create managed table " + TableNames.TRANSACTIONALTBL2 + " (id int, name string) ");
+        Table managed_table_2 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_2.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL3 + " (id int, name string) ");
+        Table managed_table_3 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_3.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL4 + " like " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_4 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL4.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_4.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL5 + " as select * from " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_5 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL5.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_5.getTableType(), table_type_managed);
+
+        LOG.info("Test execution complete:testCreateManagedTablesInDBWithDefaultTableType_External");
+    }
+
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateExternalTablesInDBWithDefaultTableType_External method for creating external tables in a special database.
+     * @throws Exception If there is an error creating external tables
+     */
+    @Test
+    public void testCreateExternalTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE1 + " (id int, name string)");
+        Table external_table_1 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_1.getTableType(), table_type_external);
+
+        runStatementOnDriver("create external table " + TableNames.EXTERNALTABLE2 + " (id int, name string) ");
+        Table external_table_2 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_2.getTableType(), table_type_external);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE3 + " like " + TableNames.EXTERNALTABLE2);
+        Table external_table_3 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_3.getTableType(), table_type_external);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE4 + " as select * from " + TableNames.EXTERNALTABLE2);
+        Table external_table_4 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE4.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_4.getTableType(), table_type_external);

Review comment:
       same here

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestDatabaseTableDefault.java
##########
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.FileUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+//import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+/**
+ * This class resides in itests to facilitate running query using Tez engine, since the jars are
+ * fully loaded here, which is not the case if it stays in ql.
+ */
+public class TestDatabaseTableDefault {
+    static final private Logger LOG = LoggerFactory.getLogger(TestDatabaseTableDefault.class);
+
+    private HiveConf hiveConf;
+    private IDriver d;
+    private static final String database_with_default_table_type = "database_with_default_table_type";
+    private static final String default_db = "default_db";
+    private static final String table_type_managed = "MANAGED_TABLE";
+    private static final String table_type_external = "EXTERNAL_TABLE";
+    File ext_wh = null;
+    File wh = null;
+    protected static HiveMetaStoreClient client;
+    protected static Configuration conf;
+    private static enum TableNames {
+        TRANSACTIONALTBL1("transactional_table_1"),
+        TRANSACTIONALTBL2("transactional_table_2"),
+        TRANSACTIONALTBL3("transactional_table_3"),
+        TRANSACTIONALTBL4("transactional_table_4"),
+        TRANSACTIONALTBL5("transactional_table_5"),
+        TRANSACTIONALTBL6("transactional_table_6"),
+        TRANSACTIONALTBL7("transactional_table_7"),
+        EXTERNALTABLE1("external_table_1"),
+        EXTERNALTABLE2("external_table_2"),
+        EXTERNALTABLE3("external_table_3"),
+        EXTERNALTABLE4("external_table_4"),
+        EXTERNALTABLE5("external_table_5"),
+        EXTERNALTABLE6("external_table_6"),
+        NONACIDPART("nonAcidPart"),
+        NONACIDNONBUCKET("nonAcidNonBucket");
+
+        private final String name;
+        @Override
+        public String toString() {
+            return name;
+        }
+        TableNames(String name) {
+            this.name = name;
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        hiveConf = new HiveConf(this.getClass());
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_CREATE_TABLES_AS_INSERT_ONLY, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, true);
+        hiveConf.set(HiveConf.ConfVars.HIVEDEFAULTMANAGEDFILEFORMAT.varname, "ORC");
+        hiveConf.setVar(HiveConf.ConfVars.HIVE_TXN_MANAGER, DbTxnManager.class.getName());
+        hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_CAPABILITIES.varname, "HIVEFULLACIDREAD,HIVEFULLACIDWRITE,HIVECACHEINVALIDATE,HIVEMANAGESTATS,HIVEMANAGEDINSERTWRITE,HIVEMANAGEDINSERTREAD");
+        TestTxnDbUtil.setConfValues(hiveConf);
+        TestTxnDbUtil.prepDb(hiveConf);
+
+        SessionState.start(new SessionState(hiveConf));
+        d = DriverFactory.newDriver(hiveConf);
+
+        wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive" + File.separator);
+        wh.mkdirs();
+
+        ext_wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive-external" + File.separator);
+        ext_wh.mkdirs();
+
+        MetastoreConf.setVar(hiveConf, ConfVars.METASTORE_METADATA_TRANSFORMER_CLASS,
+                "org.apache.hadoop.hive.metastore.MetastoreDefaultTransformer");
+        MetastoreConf.setBoolVar(hiveConf, ConfVars.HIVE_IN_TEST, false);
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE, wh.getCanonicalPath());
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE_EXTERNAL, ext_wh.getCanonicalPath());
+        MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        client = new HiveMetaStoreClient(hiveConf);
+
+
+        dropTables();
+        runStatementOnDriver("create database " + database_with_default_table_type +" with DBPROPERTIES('defaultTableType'='EXTERNAL')");
+        runStatementOnDriver("create database " + default_db);
+    }
+
+    /**
+     * this is to test differety types of Acid tables
+     */
+    String getTblProperties() {
+        return "TBLPROPERTIES ('transactional'='true')";
+    }
+
+    private void dropTables() throws Exception {
+        for(TableNames t : TableNames.values()) {
+            runStatementOnDriver("drop table if exists " + t);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        try {
+            if (d != null) {
+                dropTables();
+                runStatementOnDriver("drop database if exists " + database_with_default_table_type +" cascade");
+                runStatementOnDriver("drop database if exists " + default_db + " cascade");
+                d.close();
+                d.destroy();
+                d = null;
+            }
+        } finally {
+            FileUtils.deleteDirectory(wh);
+            FileUtils.deleteDirectory(ext_wh);
+        }
+    }
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateManagedTablesInDBWithDefaultTableType_External method for creating managed tables in a special database.
+     * @throws Exception If there is an error creating managed tables
+     */
+    @Test
+    public void testCreateManagedTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.TRANSACTIONALTBL1 + " (id int, name string) " + getTblProperties());
+        Table managed_table_1 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_1.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create managed table " + TableNames.TRANSACTIONALTBL2 + " (id int, name string) ");
+        Table managed_table_2 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_2.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL3 + " (id int, name string) ");
+        Table managed_table_3 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_3.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL4 + " like " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_4 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL4.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_4.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL5 + " as select * from " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_5 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL5.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_5.getTableType(), table_type_managed);
+
+        LOG.info("Test execution complete:testCreateManagedTablesInDBWithDefaultTableType_External");
+    }
+
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateExternalTablesInDBWithDefaultTableType_External method for creating external tables in a special database.
+     * @throws Exception If there is an error creating external tables
+     */
+    @Test
+    public void testCreateExternalTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE1 + " (id int, name string)");
+        Table external_table_1 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_1.getTableType(), table_type_external);
+
+        runStatementOnDriver("create external table " + TableNames.EXTERNALTABLE2 + " (id int, name string) ");
+        Table external_table_2 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_2.getTableType(), table_type_external);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE3 + " like " + TableNames.EXTERNALTABLE2);
+        Table external_table_3 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_3.getTableType(), table_type_external);

Review comment:
       same here

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestDatabaseTableDefault.java
##########
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.FileUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+//import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+/**
+ * This class resides in itests to facilitate running query using Tez engine, since the jars are
+ * fully loaded here, which is not the case if it stays in ql.
+ */
+public class TestDatabaseTableDefault {
+    static final private Logger LOG = LoggerFactory.getLogger(TestDatabaseTableDefault.class);
+
+    private HiveConf hiveConf;
+    private IDriver d;
+    private static final String database_with_default_table_type = "database_with_default_table_type";
+    private static final String default_db = "default_db";
+    private static final String table_type_managed = "MANAGED_TABLE";
+    private static final String table_type_external = "EXTERNAL_TABLE";
+    File ext_wh = null;
+    File wh = null;
+    protected static HiveMetaStoreClient client;
+    protected static Configuration conf;
+    private static enum TableNames {
+        TRANSACTIONALTBL1("transactional_table_1"),
+        TRANSACTIONALTBL2("transactional_table_2"),
+        TRANSACTIONALTBL3("transactional_table_3"),
+        TRANSACTIONALTBL4("transactional_table_4"),
+        TRANSACTIONALTBL5("transactional_table_5"),
+        TRANSACTIONALTBL6("transactional_table_6"),
+        TRANSACTIONALTBL7("transactional_table_7"),
+        EXTERNALTABLE1("external_table_1"),
+        EXTERNALTABLE2("external_table_2"),
+        EXTERNALTABLE3("external_table_3"),
+        EXTERNALTABLE4("external_table_4"),
+        EXTERNALTABLE5("external_table_5"),
+        EXTERNALTABLE6("external_table_6"),
+        NONACIDPART("nonAcidPart"),
+        NONACIDNONBUCKET("nonAcidNonBucket");
+
+        private final String name;
+        @Override
+        public String toString() {
+            return name;
+        }
+        TableNames(String name) {
+            this.name = name;
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        hiveConf = new HiveConf(this.getClass());
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_CREATE_TABLES_AS_INSERT_ONLY, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, true);
+        hiveConf.set(HiveConf.ConfVars.HIVEDEFAULTMANAGEDFILEFORMAT.varname, "ORC");
+        hiveConf.setVar(HiveConf.ConfVars.HIVE_TXN_MANAGER, DbTxnManager.class.getName());
+        hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_CAPABILITIES.varname, "HIVEFULLACIDREAD,HIVEFULLACIDWRITE,HIVECACHEINVALIDATE,HIVEMANAGESTATS,HIVEMANAGEDINSERTWRITE,HIVEMANAGEDINSERTREAD");
+        TestTxnDbUtil.setConfValues(hiveConf);
+        TestTxnDbUtil.prepDb(hiveConf);
+
+        SessionState.start(new SessionState(hiveConf));
+        d = DriverFactory.newDriver(hiveConf);
+
+        wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive" + File.separator);
+        wh.mkdirs();
+
+        ext_wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive-external" + File.separator);
+        ext_wh.mkdirs();
+
+        MetastoreConf.setVar(hiveConf, ConfVars.METASTORE_METADATA_TRANSFORMER_CLASS,
+                "org.apache.hadoop.hive.metastore.MetastoreDefaultTransformer");
+        MetastoreConf.setBoolVar(hiveConf, ConfVars.HIVE_IN_TEST, false);
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE, wh.getCanonicalPath());
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE_EXTERNAL, ext_wh.getCanonicalPath());
+        MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        client = new HiveMetaStoreClient(hiveConf);
+
+
+        dropTables();
+        runStatementOnDriver("create database " + database_with_default_table_type +" with DBPROPERTIES('defaultTableType'='EXTERNAL')");
+        runStatementOnDriver("create database " + default_db);
+    }
+
+    /**
+     * this is to test differety types of Acid tables
+     */
+    String getTblProperties() {
+        return "TBLPROPERTIES ('transactional'='true')";
+    }
+
+    private void dropTables() throws Exception {
+        for(TableNames t : TableNames.values()) {
+            runStatementOnDriver("drop table if exists " + t);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        try {
+            if (d != null) {
+                dropTables();
+                runStatementOnDriver("drop database if exists " + database_with_default_table_type +" cascade");
+                runStatementOnDriver("drop database if exists " + default_db + " cascade");
+                d.close();
+                d.destroy();
+                d = null;
+            }
+        } finally {
+            FileUtils.deleteDirectory(wh);
+            FileUtils.deleteDirectory(ext_wh);
+        }
+    }
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateManagedTablesInDBWithDefaultTableType_External method for creating managed tables in a special database.
+     * @throws Exception If there is an error creating managed tables
+     */
+    @Test
+    public void testCreateManagedTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.TRANSACTIONALTBL1 + " (id int, name string) " + getTblProperties());
+        Table managed_table_1 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_1.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create managed table " + TableNames.TRANSACTIONALTBL2 + " (id int, name string) ");
+        Table managed_table_2 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_2.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL3 + " (id int, name string) ");
+        Table managed_table_3 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_3.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL4 + " like " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_4 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL4.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_4.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL5 + " as select * from " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_5 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL5.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_5.getTableType(), table_type_managed);
+
+        LOG.info("Test execution complete:testCreateManagedTablesInDBWithDefaultTableType_External");
+    }
+
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateExternalTablesInDBWithDefaultTableType_External method for creating external tables in a special database.
+     * @throws Exception If there is an error creating external tables
+     */
+    @Test
+    public void testCreateExternalTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE1 + " (id int, name string)");
+        Table external_table_1 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_1.getTableType(), table_type_external);

Review comment:
       This message is incorrect. We are expecting external tabletype not managed.

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestDatabaseTableDefault.java
##########
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.FileUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+//import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+/**
+ * This class resides in itests to facilitate running query using Tez engine, since the jars are
+ * fully loaded here, which is not the case if it stays in ql.
+ */
+public class TestDatabaseTableDefault {
+    static final private Logger LOG = LoggerFactory.getLogger(TestDatabaseTableDefault.class);
+
+    private HiveConf hiveConf;
+    private IDriver d;
+    private static final String database_with_default_table_type = "database_with_default_table_type";
+    private static final String default_db = "default_db";
+    private static final String table_type_managed = "MANAGED_TABLE";
+    private static final String table_type_external = "EXTERNAL_TABLE";
+    File ext_wh = null;
+    File wh = null;
+    protected static HiveMetaStoreClient client;
+    protected static Configuration conf;
+    private static enum TableNames {
+        TRANSACTIONALTBL1("transactional_table_1"),
+        TRANSACTIONALTBL2("transactional_table_2"),
+        TRANSACTIONALTBL3("transactional_table_3"),
+        TRANSACTIONALTBL4("transactional_table_4"),
+        TRANSACTIONALTBL5("transactional_table_5"),
+        TRANSACTIONALTBL6("transactional_table_6"),
+        TRANSACTIONALTBL7("transactional_table_7"),
+        EXTERNALTABLE1("external_table_1"),
+        EXTERNALTABLE2("external_table_2"),
+        EXTERNALTABLE3("external_table_3"),
+        EXTERNALTABLE4("external_table_4"),
+        EXTERNALTABLE5("external_table_5"),
+        EXTERNALTABLE6("external_table_6"),
+        NONACIDPART("nonAcidPart"),
+        NONACIDNONBUCKET("nonAcidNonBucket");
+
+        private final String name;
+        @Override
+        public String toString() {
+            return name;
+        }
+        TableNames(String name) {
+            this.name = name;
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        hiveConf = new HiveConf(this.getClass());
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_CREATE_TABLES_AS_INSERT_ONLY, true);
+        HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, true);
+        hiveConf.set(HiveConf.ConfVars.HIVEDEFAULTMANAGEDFILEFORMAT.varname, "ORC");
+        hiveConf.setVar(HiveConf.ConfVars.HIVE_TXN_MANAGER, DbTxnManager.class.getName());
+        hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_CAPABILITIES.varname, "HIVEFULLACIDREAD,HIVEFULLACIDWRITE,HIVECACHEINVALIDATE,HIVEMANAGESTATS,HIVEMANAGEDINSERTWRITE,HIVEMANAGEDINSERTREAD");
+        TestTxnDbUtil.setConfValues(hiveConf);
+        TestTxnDbUtil.prepDb(hiveConf);
+
+        SessionState.start(new SessionState(hiveConf));
+        d = DriverFactory.newDriver(hiveConf);
+
+        wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive" + File.separator);
+        wh.mkdirs();
+
+        ext_wh = new File(System.getProperty("java.io.tmpdir") + File.separator +
+                "hive" + File.separator + "warehouse" + File.separator + "hive-external" + File.separator);
+        ext_wh.mkdirs();
+
+        MetastoreConf.setVar(hiveConf, ConfVars.METASTORE_METADATA_TRANSFORMER_CLASS,
+                "org.apache.hadoop.hive.metastore.MetastoreDefaultTransformer");
+        MetastoreConf.setBoolVar(hiveConf, ConfVars.HIVE_IN_TEST, false);
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE, wh.getCanonicalPath());
+        MetastoreConf.setVar(hiveConf, ConfVars.WAREHOUSE_EXTERNAL, ext_wh.getCanonicalPath());
+        MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.CREATE_TABLES_AS_ACID, true);
+        client = new HiveMetaStoreClient(hiveConf);
+
+
+        dropTables();
+        runStatementOnDriver("create database " + database_with_default_table_type +" with DBPROPERTIES('defaultTableType'='EXTERNAL')");
+        runStatementOnDriver("create database " + default_db);
+    }
+
+    /**
+     * this is to test differety types of Acid tables
+     */
+    String getTblProperties() {
+        return "TBLPROPERTIES ('transactional'='true')";
+    }
+
+    private void dropTables() throws Exception {
+        for(TableNames t : TableNames.values()) {
+            runStatementOnDriver("drop table if exists " + t);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        try {
+            if (d != null) {
+                dropTables();
+                runStatementOnDriver("drop database if exists " + database_with_default_table_type +" cascade");
+                runStatementOnDriver("drop database if exists " + default_db + " cascade");
+                d.close();
+                d.destroy();
+                d = null;
+            }
+        } finally {
+            FileUtils.deleteDirectory(wh);
+            FileUtils.deleteDirectory(ext_wh);
+        }
+    }
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateManagedTablesInDBWithDefaultTableType_External method for creating managed tables in a special database.
+     * @throws Exception If there is an error creating managed tables
+     */
+    @Test
+    public void testCreateManagedTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.TRANSACTIONALTBL1 + " (id int, name string) " + getTblProperties());
+        Table managed_table_1 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_1.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create managed table " + TableNames.TRANSACTIONALTBL2 + " (id int, name string) ");
+        Table managed_table_2 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_2.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL3 + " (id int, name string) ");
+        Table managed_table_3 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_3.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL4 + " like " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_4 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL4.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_4.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create transactional table " + TableNames.TRANSACTIONALTBL5 + " as select * from " + TableNames.TRANSACTIONALTBL3);
+        Table managed_table_5 = client.getTable(database_with_default_table_type, TableNames.TRANSACTIONALTBL5.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_5.getTableType(), table_type_managed);
+
+        LOG.info("Test execution complete:testCreateManagedTablesInDBWithDefaultTableType_External");
+    }
+
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateExternalTablesInDBWithDefaultTableType_External method for creating external tables in a special database.
+     * @throws Exception If there is an error creating external tables
+     */
+    @Test
+    public void testCreateExternalTablesInDBWithDefaultTableType_External() throws Exception {
+        runStatementOnDriver("use " + database_with_default_table_type);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE1 + " (id int, name string)");
+        Table external_table_1 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE1.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_1.getTableType(), table_type_external);
+
+        runStatementOnDriver("create external table " + TableNames.EXTERNALTABLE2 + " (id int, name string) ");
+        Table external_table_2 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE2.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_2.getTableType(), table_type_external);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE3 + " like " + TableNames.EXTERNALTABLE2);
+        Table external_table_3 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE3.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_3.getTableType(), table_type_external);
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE4 + " as select * from " + TableNames.EXTERNALTABLE2);
+        Table external_table_4 = client.getTable(database_with_default_table_type, TableNames.EXTERNALTABLE4.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_4.getTableType(), table_type_external);
+
+        LOG.info("Test execution complete:testCreateExternalTablesInDBWithDefaultTableType_External");
+    }
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateTablesInAlterDBSetDefaultTableType method for creating external tables in altered database.
+     * @throws Exception If there is an error creating managed tables
+     */
+    @Test
+    public void testCreateTablesInAlterDBSetDefaultTableType() throws Exception {
+        String altered_db = "altered_db";
+        runStatementOnDriver("create database "+altered_db);
+        runStatementOnDriver("use "+altered_db);
+
+        runStatementOnDriver("create table " + TableNames.TRANSACTIONALTBL6 + " (id int, name string)");
+        Table managed_table_6 = client.getTable(altered_db, TableNames.TRANSACTIONALTBL6.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_6.getTableType(), table_type_managed);
+
+        runStatementOnDriver("alter database " + altered_db + " set DBPROPERTIES (\"defaultTableType\"=\"EXTERNAL\")");
+
+        runStatementOnDriver("create table " + TableNames.EXTERNALTABLE5 + " (id int, name string)");
+        Table external_table_5 = client.getTable(altered_db, TableNames.EXTERNALTABLE5.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_5.getTableType(), table_type_external);
+
+        runStatementOnDriver("drop database " + altered_db + " cascade");
+        LOG.info("Test execution complete:testAlterExternalTables");
+    }
+
+    /**
+     * Tests the TestDatabaseTableDefault.testCreateTablesInDBWithDefaultTableTypeAcid method for creating acid tables in the database by default.
+     * @throws Exception If there is an error creating managed tables
+     */
+    @Test
+    public void testCreateTablesInDBWithDefaultTableTypeAcid() throws Exception {
+        String acid_database = "acid_database";
+        runStatementOnDriver("create database "+acid_database+" with DBPROPERTIES('defaultTableType'='ACID')");
+        runStatementOnDriver("use "+acid_database);
+
+        runStatementOnDriver("create table " + TableNames.TRANSACTIONALTBL7 + " (id int, name string)");
+        Table managed_table_7 = client.getTable(acid_database, TableNames.TRANSACTIONALTBL7.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", managed_table_7.getTableType(), table_type_managed);
+
+        runStatementOnDriver("create external table " + TableNames.EXTERNALTABLE6 + " (id int, name string)");
+        Table external_table_6 = client.getTable(acid_database, TableNames.EXTERNALTABLE6.toString());
+        assertEquals("Created table type is expected to be managed but found to be external", external_table_6.getTableType(), table_type_external);

Review comment:
       message incorrect




-- 
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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 730918)
    Time Spent: 2h  (was: 1h 50m)

> Support table defaults at each database level
> ---------------------------------------------
>
>                 Key: HIVE-25826
>                 URL: https://issues.apache.org/jira/browse/HIVE-25826
>             Project: Hive
>          Issue Type: New Feature
>          Components: HiveServer2, Standalone Metastore
>            Reporter: Sai Hemanth Gantasala
>            Assignee: Sai Hemanth Gantasala
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> This feature jira is for adding support for users being able to specify default table types at each database level. Currently, this is configurable at the service level (HS2) and at each JDBC session-level. The goal is to be able to specify the default table type for each database either when the DB is created (create DB DDL) or at any point later (via alter db DDL).
> More details and design docs for this feature will be added soon to this Jira.



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