This is an automated email from the ASF dual-hosted git repository.

gsaihemanth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e9695cbdde HIVE-27892: Hive 'insert overwrite table' for multiple 
partition table issue (#4893) (Mayank Kunwar, Reviewed by Sai Hemanth Gantasala)
5e9695cbdde is described below

commit 5e9695cbdded7d7a40ecd9fc93ee6803625bb197
Author: Mayank Kunwar <[email protected]>
AuthorDate: Wed Dec 13 23:08:54 2023 +0530

    HIVE-27892: Hive 'insert overwrite table' for multiple partition table 
issue (#4893) (Mayank Kunwar, Reviewed by Sai Hemanth Gantasala)
---
 .../hadoop/hive/ql/parse/SemanticAnalyzer.java     |  8 +++++-
 .../authorization/command/CommandAuthorizerV2.java |  8 ++++--
 .../TestHivePrivilegeObjectOwnerNameAndType.java   | 33 ++++++++++++++++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
index 0823b6d9ba4..2f386931957 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
@@ -8640,7 +8640,13 @@ public class SemanticAnalyzer extends 
BaseSemanticAnalyzer {
                 new DummyPartition(dest_tab, dest_tab.getDbName()
                         + "@" + dest_tab.getTableName() + "@" + ppath,
                         partSpec);
-        output = new WriteEntity(p, getWriteType(dest), false);
+        WriteEntity.WriteType writeType;
+        if (ltd.isInsertOverwrite()) {
+          writeType = WriteEntity.WriteType.INSERT_OVERWRITE;
+        } else {
+          writeType = getWriteType(dest);
+        }
+        output = new WriteEntity(p, writeType, false);
         output.setDynamicPartitionWrite(true);
         outputs.add(output);
       }
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/command/CommandAuthorizerV2.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/command/CommandAuthorizerV2.java
index 08e016223e4..50fc7975da1 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/command/CommandAuthorizerV2.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/command/CommandAuthorizerV2.java
@@ -233,8 +233,12 @@ final class CommandAuthorizerV2 {
       break;
     case DUMMYPARTITION:
     case PARTITION:
-      // TODO: not currently handled
-      return;
+      Table tbl = privObject.getTable();
+      List<String> col = tableName2Cols == null ? null :
+              tableName2Cols.get(Table.getCompleteName(tbl.getDbName(), 
tbl.getTableName()));
+      hivePrivObject = new HivePrivilegeObject(privObjType, tbl.getDbName(), 
tbl.getTableName(),
+              null, col, actionType, null, null, tbl.getOwner(), 
tbl.getOwnerType());
+      break;
     case SERVICE_NAME:
       hivePrivObject = new HivePrivilegeObject(privObjType, null, 
privObject.getServiceName(), null,
           null, actionType, null, null, null, null);
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHivePrivilegeObjectOwnerNameAndType.java
 
b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHivePrivilegeObjectOwnerNameAndType.java
index a04e5f0227b..410d9b7d918 100644
--- 
a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHivePrivilegeObjectOwnerNameAndType.java
+++ 
b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHivePrivilegeObjectOwnerNameAndType.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
 import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
 import org.apache.hadoop.hive.ql.Driver;
 import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+import 
org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject;
 import org.apache.hadoop.hive.ql.security.HiveAuthenticationProvider;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.security.UserGroupInformation;
@@ -77,6 +78,7 @@ public class TestHivePrivilegeObjectOwnerNameAndType {
     conf.setBoolVar(ConfVars.HIVE_SUPPORT_CONCURRENCY, true);
     conf.setVar(ConfVars.HIVE_TXN_MANAGER, DbTxnManager.class.getName());
     conf.setVar(ConfVars.HIVEMAPREDMODE, "nonstrict");
+    conf.setVar(ConfVars.DYNAMICPARTITIONINGMODE, "nonstrict");
 
     TestTxnDbUtil.prepDb(conf);
     SessionState.start(conf);
@@ -145,6 +147,37 @@ public class TestHivePrivilegeObjectOwnerNameAndType {
     Assert.assertTrue(containsOwnerType);
   }
 
+  @Test
+  public void testActionTypeForPartitionedTable() throws Exception {
+    runCmd("CREATE EXTERNAL TABLE Part (eid int, name int) PARTITIONED BY 
(position int, dept int, sal int)");
+    reset(mockedAuthorizer);
+    runCmd("insert overwrite table part partition(position=2,DEPT,SAL) select 
2,2,2,2");
+    Pair<List<HivePrivilegeObject>, List<HivePrivilegeObject>> io = 
getHivePrivilegeObjectInputs();
+    List<HivePrivilegeObject> hpoList = io.getValue();
+    Assert.assertFalse(hpoList.isEmpty());
+    for (HivePrivilegeObject hpo : hpoList) {
+      Assert.assertEquals(hpo.getActionType(), 
HivePrivilegeObject.HivePrivObjectActionType.INSERT_OVERWRITE);
+    }
+  }
+
+  /**
+   * Test to check, if only single instance of Hive Privilege object is 
created,
+   * during bulk insert into a partitioned table.
+   */
+  @Test
+  public void testSingleInstanceOfHPOForPartitionedTable() throws Exception {
+    reset(mockedAuthorizer);
+    runCmd("insert overwrite table part partition(position=2,DEPT,SAL)" +
+            " select 2,2,2,2" +
+            " union all" +
+            " select 1,2,3,4" +
+            " union all" +
+            " select 3,4,5,6");
+    Pair<List<HivePrivilegeObject>, List<HivePrivilegeObject>> io = 
getHivePrivilegeObjectInputs();
+    List<HivePrivilegeObject> hpoList = io.getValue();
+    Assert.assertEquals(1, hpoList.size());
+  }
+
   /**
    * @return pair with left value as inputs and right value as outputs,
    *  passed in current call to authorizer.checkPrivileges

Reply via email to