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/03/21 22:45:00 UTC

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

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

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

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



##########
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:
       not sure why we are using the default of "none" if not set. We are not doing anything with the value. why not just allow it to return a null when not set, and check for null?

##########
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:
       nit: rearrange imports in the alphabetical order

##########
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:
       nit: typo in different

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

Review comment:
       nit: this line should be deleted

##########
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:
       its not clear where the value for isDefaultTableTypeChanged is coming from in analyzeCreateTable method. The "View file" only shows about 12k lines (a truncated version of this file)

##########
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:
       nit: remove extra empty line

##########
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:
       can you please add comments on what this method is supposed to do? it is a bit confusing when this is meant to be used. 




-- 
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: 745497)
    Time Spent: 2h 10m  (was: 2h)

> 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 10m
>  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)