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/03/22 21:54:05 UTC

[GitHub] [hive] saihemanth-cloudera commented on a change in pull request #2924: HIVE-25826: Support table default types at each database level

saihemanth-cloudera commented on a change in pull request #2924:
URL: https://github.com/apache/hive/pull/2924#discussion_r832659200



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
##########
@@ -13625,7 +13656,8 @@ ASTNode analyzeCreateTable(
       }
       tblProps = validateAndAddDefaultProperties(
           tblProps, isExt, storageFormat, dbDotTab, sortCols, isMaterialization, isTemporary,
-          isTransactional, isManaged);
+          isTransactional, isManaged, new String[] {qualifiedTabName.getDb(), qualifiedTabName.getTable()}, isDefaultTableTypeChanged);

Review comment:
       This flag is used as one of the determining factors in the validateAndAddDefaultProperties() to decide whether to create an acid table or managed table.

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
##########
@@ -13615,7 +13631,22 @@ ASTNode analyzeCreateTable(
 
     // Handle different types of CREATE TABLE command
     // Note: each branch must call addDbAndTabToOutputs after finalizing table properties.
-
+    Database database  = getDatabase(qualifiedTabName.getDb());
+    boolean isDefaultTableTypeChanged = false;
+    if(database.getParameters() != null) {
+      String defaultTableType = database.getParameters().getOrDefault(DEFAULT_TABLE_TYPE, "none");

Review comment:
       Ack

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
##########
@@ -13245,9 +13247,23 @@ private void updateDefaultTblProps(Map<String, String> source, Map<String, Strin
         retValue = convertToAcidByDefault(storageFormat, qualifiedTableName, sortCols, retValue);
       }
     }
+    if (!isExt) {
+      addDbAndTabToOutputs(qualifiedTabName,
+              TableType.MANAGED_TABLE, isTemporaryTable, retValue, storageFormat);
+    } else {
+      addDbAndTabToOutputs(qualifiedTabName,
+              TableType.EXTERNAL_TABLE, isTemporaryTable, retValue, storageFormat);
+    }
     return retValue;
   }
 
+  private boolean isExternalTableChanged (Map<String, String> tblProp, boolean isTransactional, boolean isExt, boolean isTableTypeChanged) {

Review comment:
       ack

##########
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);
+
+

Review comment:
       ack

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

Review comment:
       Ack

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

Review comment:
       Ack




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