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

dkuzmenko 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 e775424a411 HIVE-26479: Add ability to set parameters for query-based 
compaction (Sourabh Badhya, reviewed by Denys Kuzmenko)
e775424a411 is described below

commit e775424a4118bac72b237f2eb4d586b6030ee1c6
Author: Sourabh Badhya <[email protected]>
AuthorDate: Tue Aug 30 12:44:09 2022 +0530

    HIVE-26479: Add ability to set parameters for query-based compaction 
(Sourabh Badhya, reviewed by Denys Kuzmenko)
    
    Closes #3528
---
 .../apache/hadoop/hive/common/StringableMap.java   | 107 ---------------
 .../hive/ql/txn/compactor/CompactorOnTezTest.java  |  36 +++++-
 .../ql/txn/compactor/TestCrudCompactorOnTez.java   | 144 +++++++++++++++++++--
 .../ql/txn/compactor/TestMRCompactorOnTez.java     |   1 -
 .../ql/txn/compactor/TestMmCompactorOnTez.java     |   2 +-
 .../hadoop/hive/ql/txn/compactor/CompactorMR.java  |   2 +-
 .../hive/ql/txn/compactor/CompactorUtil.java       |   2 +-
 .../hive/ql/txn/compactor/MajorQueryCompactor.java |   3 +-
 .../hive/ql/txn/compactor/MinorQueryCompactor.java |   2 +-
 .../ql/txn/compactor/MmMajorQueryCompactor.java    |   3 +-
 .../ql/txn/compactor/MmMinorQueryCompactor.java    |   2 +-
 .../hive/ql/txn/compactor/QueryCompactor.java      |  21 ++-
 .../TestCompactorMRJobQueueConfiguration.java      |   2 +-
 .../hadoop/hive/ql/txn/compactor/TestWorker.java   |   2 +-
 .../hadoop/hive/metastore/utils/StringableMap.java |  41 +++++-
 15 files changed, 233 insertions(+), 137 deletions(-)

diff --git a/common/src/java/org/apache/hadoop/hive/common/StringableMap.java 
b/common/src/java/org/apache/hadoop/hive/common/StringableMap.java
deleted file mode 100644
index c495e10cac0..00000000000
--- a/common/src/java/org/apache/hadoop/hive/common/StringableMap.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.common;
-
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * A utility class that can convert a HashMap of Properties into a colon 
separated string,
- * and can take the same format of string and convert it to a HashMap of 
Properties.
- */
-public class StringableMap extends HashMap<String, String> {
-
-  public StringableMap(String s) {
-    String[] parts = s.split(":", 2);
-    // read that many chars
-    int numElements = Integer.parseInt(parts[0]);
-    s = parts[1];
-    for (int i = 0; i < numElements; i++) {
-      // Get the key String.
-      parts = s.split(":", 2);
-      int len = Integer.parseInt(parts[0]);             
-      String key = "";     // Default is now an empty string.
-
-      if (len > 0) key = parts[1].substring(0, len);    
-      // Please check the toString() method of this class.
-      // null has -1 as length and empty String has 0.
-      else if (len < 0) {
-         key = null;
-         len = 0;         // Set 0 to 'len' for null-valued key 
-                          // since only len exists for null-valued key from 
the given String "s".     
-      }
-      
-      // Get the value String for the key
-      parts = parts[1].substring(len).split(":", 2);
-      len = Integer.parseInt(parts[0]);
-      String value = "";
-
-      if (len > 0) value = parts[1].substring(0, len);
-      else if (len < 0) {
-         value = null; 
-         len = 0;        // Set 0 to 'len' since only len exists.
-      }
-      
-      // Put the entry into the HashMap<String, String>.
-      put(key, value);
-      
-      // Move to the next substring to process.
-      s = parts[1].substring(len);
-    }
-  }
-
-  public StringableMap(Map<String, String> m) {
-    super(m);
-  }
-
-  @Override
-  public String toString() {
-    StringBuilder buf = new StringBuilder();
-    buf.append(size());
-    buf.append(':');
-    if (size() > 0) {
-      for (Map.Entry<String, String> entry : entrySet()) {
-       // Append the key String to the output StringBuilder.
-        // Note that null is saved as -1 in length, and that empty String as 0.
-       int length = (entry.getKey() == null) ? -1 : entry.getKey().length();
-       buf.append(length);
-        buf.append(':');
-        if (length > 0) buf.append(entry.getKey());
-        
-        // Append the value String to the output StringBuilder.
-        // Note that null is saved as -1 in length, and that empty String as 0.
-        length = (entry.getValue() == null) ? -1 : entry.getValue().length();
-        buf.append(length);
-        buf.append(':');
-        if (length > 0) {
-               buf.append(entry.getValue());
-        }
-      }
-    }
-    return buf.toString();
-  }
-
-  public Properties toProperties() {
-    Properties props = new Properties();
-    props.putAll(this);
-    return props;
-  }
-}
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorOnTezTest.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorOnTezTest.java
index e96b2fd6119..d06385ef160 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorOnTezTest.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorOnTezTest.java
@@ -30,12 +30,17 @@ import org.apache.hadoop.hive.metastore.txn.TxnUtils;
 import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
 import org.apache.hadoop.hive.ql.DriverFactory;
 import org.apache.hadoop.hive.ql.IDriver;
+import org.apache.hadoop.hive.ql.hooks.HiveProtoLoggingHook.ExecutionMode;
+import org.apache.hadoop.hive.ql.hooks.TestHiveProtoLoggingHook;
+import org.apache.hadoop.hive.ql.hooks.proto.HiveHookEvents;
 import org.apache.hadoop.hive.ql.io.HiveInputFormat;
 import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.tez.dag.history.logging.proto.ProtoMessageReader;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Rule;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.rules.TemporaryFolder;
 
 import java.io.File;
@@ -68,8 +73,10 @@ public abstract class CompactorOnTezTest {
   protected IDriver driver;
   protected boolean mmCompaction = false;
 
-  @Rule
-  public TemporaryFolder folder = new TemporaryFolder();
+  @ClassRule
+  public static TemporaryFolder folder = new TemporaryFolder();
+
+  public static String tmpFolder;
 
   @Before
   // Note: we create a new conf and driver object before every test
@@ -78,6 +85,11 @@ public abstract class CompactorOnTezTest {
     setupWithConf(hiveConf);
   }
 
+  @BeforeClass
+  public static void setupClass() throws Exception {
+    tmpFolder = folder.newFolder().getAbsolutePath();
+  }
+
   protected void setupWithConf(HiveConf hiveConf) throws Exception {
     File f = new File(TEST_WAREHOUSE_DIR);
     if (f.exists()) {
@@ -158,6 +170,24 @@ public abstract class CompactorOnTezTest {
         c -> Assert.assertEquals("Compaction state is not succeeded", 
"succeeded", c.getState()));
   }
 
+  protected HiveHookEvents.HiveHookEventProto getRelatedTezEvent(String 
dbTableName) throws Exception {
+    ProtoMessageReader<HiveHookEvents.HiveHookEventProto> reader = 
TestHiveProtoLoggingHook.getTestReader(conf, tmpFolder);
+    HiveHookEvents.HiveHookEventProto event = reader.readEvent();
+    boolean getRelatedEvent = false;
+    while (!getRelatedEvent) {
+      while (ExecutionMode.TEZ != 
ExecutionMode.valueOf(event.getExecutionMode())) {
+        event = reader.readEvent();
+      }
+      // Tables read is the table picked for compaction.
+      if (event.getTablesReadCount() > 0 && 
dbTableName.equalsIgnoreCase(event.getTablesRead(0))) {
+        getRelatedEvent = true;
+      } else {
+        event = reader.readEvent();
+      }
+    }
+    return event;
+  }
+
   protected class TestDataProvider {
 
     void createFullAcidTable(String tblName, boolean isPartitioned, boolean 
isBucketed)
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestCrudCompactorOnTez.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestCrudCompactorOnTez.java
index a60a8d964dc..9d41bb72f44 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestCrudCompactorOnTez.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestCrudCompactorOnTez.java
@@ -368,11 +368,11 @@ public class TestCrudCompactorOnTez extends 
CompactorOnTezTest {
     conf.setBoolVar(HiveConf.ConfVars.HIVE_WRITE_ACID_VERSION_FILE, true);
 
     conf.setVar(HiveConf.ConfVars.COMPACTOR_JOB_QUEUE, 
CUSTOM_COMPACTION_QUEUE);
-    String tmpFolder = folder.newFolder().getAbsolutePath();
     conf.setVar(HiveConf.ConfVars.HIVE_PROTO_EVENTS_BASE_PATH, tmpFolder);
 
     String dbName = "default";
     String tblName = "testMajorCompaction";
+    String dbTableName = dbName + "." + tblName;
     TestDataProvider testDataProvider = new TestDataProvider();
     testDataProvider.createFullAcidTable(tblName, false, false);
     testDataProvider.insertTestData(tblName);
@@ -434,11 +434,7 @@ public class TestCrudCompactorOnTez extends 
CompactorOnTezTest {
         new String[] { AcidUtils.BASE_PREFIX});
     conf.setBoolVar(HiveConf.ConfVars.HIVE_WRITE_ACID_VERSION_FILE, 
originalEnableVersionFile);
 
-    ProtoMessageReader<HiveHookEvents.HiveHookEventProto> reader = 
TestHiveProtoLoggingHook.getTestReader(conf, tmpFolder);
-    HiveHookEvents.HiveHookEventProto event = reader.readEvent();
-    while (ExecutionMode.TEZ != 
ExecutionMode.valueOf(event.getExecutionMode())) {
-      event = reader.readEvent();
-    }
+    HiveHookEvents.HiveHookEventProto event = getRelatedTezEvent(dbTableName);
     Assert.assertNotNull(event);
     Assert.assertEquals(event.getQueue(), CUSTOM_COMPACTION_QUEUE);
   }
@@ -2251,12 +2247,12 @@ public class TestCrudCompactorOnTez extends 
CompactorOnTezTest {
     hiveConf.set(ValidTxnList.VALID_TXNS_KEY, "8:9223372036854775807::");
 
     // Check for default case.
-    qc.runCompactionQueries(hiveConf, null, sdMock, null, ciMock, null, 
emptyQueries, emptyQueries, emptyQueries);
+    qc.runCompactionQueries(hiveConf, null, sdMock, null, ciMock, null, 
emptyQueries, emptyQueries, emptyQueries, null);
     Assert.assertEquals("all", 
hiveConf.getVar(HiveConf.ConfVars.LLAP_IO_ETL_SKIP_FORMAT));
 
     // Check for case where  hive.llap.io.etl.skip.format is explicitly set to 
none - as to always use cache.
     hiveConf.setVar(HiveConf.ConfVars.LLAP_IO_ETL_SKIP_FORMAT, "none");
-    qc.runCompactionQueries(hiveConf, null, sdMock, null, ciMock, null, 
emptyQueries, emptyQueries, emptyQueries);
+    qc.runCompactionQueries(hiveConf, null, sdMock, null, ciMock, null, 
emptyQueries, emptyQueries, emptyQueries, null);
     Assert.assertEquals("none", 
hiveConf.getVar(HiveConf.ConfVars.LLAP_IO_ETL_SKIP_FORMAT));
   }
 
@@ -2416,4 +2412,136 @@ public class TestCrudCompactorOnTez extends 
CompactorOnTezTest {
     Assert.assertEquals(expectedData, actualData);
   }
 
+  @Test
+  public void testCompactionWithCreateTableProps() throws Exception {
+    conf.setBoolVar(HiveConf.ConfVars.COMPACTOR_CRUD_QUERY_BASED, true);
+    conf.setVar(HiveConf.ConfVars.HIVE_PROTO_EVENTS_BASE_PATH, tmpFolder);
+
+    String dbName = "default";
+    String tblName = "comp_with_create_tblprops_test";
+    String dbTableName = dbName + "." + tblName;
+
+    TxnStore txnHandler = TxnUtils.getTxnStore(conf);
+    TestDataProvider testDP = new TestDataProvider();
+
+    // Create test table
+    executeStatementOnDriver("drop table if exists " + tblName, driver);
+    executeStatementOnDriver("CREATE TABLE " + tblName + "(col1 
array<struct<arr_col1:int, `timestamp`:string>>)" +
+            "STORED AS ORC TBLPROPERTIES('transactional'='true', 
'compactor.tez.task.resource.memory.mb'='8000')", driver);
+
+    // Insert test data into test table
+    executeStatementOnDriver("INSERT INTO TABLE " + tblName +
+            " SELECT ARRAY(NAMED_STRUCT('arr_col1',1,'timestamp','2022-07-05 
21:51:20.371'))",driver);
+    executeStatementOnDriver("INSERT INTO TABLE " + tblName +
+            " SELECT ARRAY(NAMED_STRUCT('arr_col1',2,'timestamp','2022-07-06 
21:51:20.371'))",driver);
+
+    // Get all data before compaction is run
+    List<String> expectedData = testDP.getAllData(tblName);
+
+    // Initiate a compaction request.
+    CompactionRequest rqst = new CompactionRequest(dbName, tblName, 
CompactionType.MAJOR);
+    CompactionResponse resp = txnHandler.compact(rqst);
+
+    conf.setVar(HiveConf.ConfVars.PREEXECHOOKS, 
HiveProtoLoggingHook.class.getName());
+    // Run major compaction and cleaner
+    runWorker(conf);
+    conf.setVar(HiveConf.ConfVars.PREEXECHOOKS, StringUtils.EMPTY);
+
+    CompactorTestUtil.runCleaner(conf);
+
+    //Check if the compaction succeeds
+    ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
+    List<ShowCompactResponseElement> compacts = rsp.getCompacts();
+    Assert.assertEquals("Expecting 1 rows and found " + compacts.size(), 1, 
compacts.size());
+    Assert.assertEquals("Expecting compaction state 'succeeded' and found:" + 
compacts.get(0).getState(),
+            "succeeded", compacts.get(0).getState());
+
+    IMetaStoreClient msClient = new HiveMetaStoreClient(conf);
+    Table table = msClient.getTable(dbName, tblName);
+
+    FileSystem fs = FileSystem.get(conf);
+    FileStatus[] fileStatus = fs.listStatus(new 
Path(table.getSd().getLocation()));
+    for(FileStatus file: fileStatus) {
+      
Assert.assertTrue(file.getPath().getName().startsWith(AcidUtils.BASE_PREFIX));
+    }
+
+    // Verify all contents
+    List<String> actualData = testDP.getAllData(tblName);
+    Assert.assertEquals(expectedData, actualData);
+
+    HiveHookEvents.HiveHookEventProto event = getRelatedTezEvent(dbTableName);
+    Assert.assertNotNull(event);
+
+    for (org.apache.hadoop.hive.ql.hooks.proto.HiveHookEvents.MapFieldEntry 
mapFieldEntry: event.getOtherInfoList()) {
+      if (mapFieldEntry.getKey().equalsIgnoreCase("CONF")) {
+        
Assert.assertTrue(mapFieldEntry.getValue().contains("\"tez.task.resource.memory.mb\":\"8000\""));
+      }
+    }
+  }
+
+  @Test
+  public void testCompactionWithAlterTableProps() throws Exception {
+    conf.setBoolVar(HiveConf.ConfVars.COMPACTOR_CRUD_QUERY_BASED, true);
+    conf.setVar(HiveConf.ConfVars.HIVE_PROTO_EVENTS_BASE_PATH, tmpFolder);
+
+    String dbName = "default";
+    String tblName = "comp_with_alter_tblprops_test";
+    String dbTableName = dbName + "." + tblName;
+
+    TxnStore txnHandler = TxnUtils.getTxnStore(conf);
+    TestDataProvider testDP = new TestDataProvider();
+
+    // Create test table
+    executeStatementOnDriver("drop table if exists " + tblName, driver);
+    executeStatementOnDriver("CREATE TABLE " + tblName + "(col1 
array<struct<arr_col1:int, `timestamp`:string>>)" +
+            "STORED AS ORC TBLPROPERTIES('transactional'='true', 
'compactor.tez.task.resource.memory.mb'='8000')", driver);
+
+    // Insert test data into test table
+    executeStatementOnDriver("INSERT INTO TABLE " + tblName +
+            " SELECT ARRAY(NAMED_STRUCT('arr_col1',1,'timestamp','2022-07-05 
21:51:20.371'))",driver);
+    executeStatementOnDriver("INSERT INTO TABLE " + tblName +
+            " SELECT ARRAY(NAMED_STRUCT('arr_col1',2,'timestamp','2022-07-05 
21:51:20.371'))",driver);
+
+    executeStatementOnDriver("ALTER TABLE " + tblName + " COMPACT 'major' WITH 
OVERWRITE TBLPROPERTIES " +
+            "('compactor.tez.task.resource.memory.mb'='5000')", driver);
+
+    // Get all data before compaction is run
+    List<String> expectedData = testDP.getAllData(tblName);
+
+    conf.setVar(HiveConf.ConfVars.PREEXECHOOKS, 
HiveProtoLoggingHook.class.getName());
+    // Run major compaction and cleaner
+    runWorker(conf);
+    conf.setVar(HiveConf.ConfVars.PREEXECHOOKS, StringUtils.EMPTY);
+
+    CompactorTestUtil.runCleaner(conf);
+
+    //Check if the compaction succeeds
+    ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
+    List<ShowCompactResponseElement> compacts = rsp.getCompacts();
+    Assert.assertEquals("Expecting 1 rows and found " + compacts.size(), 1, 
compacts.size());
+    Assert.assertEquals("Expecting compaction state 'succeeded' and found:" + 
compacts.get(0).getState(),
+            "succeeded", compacts.get(0).getState());
+
+    IMetaStoreClient msClient = new HiveMetaStoreClient(conf);
+    Table table = msClient.getTable(dbName, tblName);
+
+    FileSystem fs = FileSystem.get(conf);
+    FileStatus[] fileStatus = fs.listStatus(new 
Path(table.getSd().getLocation()));
+    for(FileStatus file: fileStatus) {
+      
Assert.assertTrue(file.getPath().getName().startsWith(AcidUtils.BASE_PREFIX));
+    }
+
+    // Verify all contents
+    List<String> actualData = testDP.getAllData(tblName);
+    Assert.assertEquals(expectedData, actualData);
+
+    HiveHookEvents.HiveHookEventProto event = getRelatedTezEvent(dbTableName);
+    Assert.assertNotNull(event);
+
+    for (org.apache.hadoop.hive.ql.hooks.proto.HiveHookEvents.MapFieldEntry 
mapFieldEntry: event.getOtherInfoList()) {
+      if (mapFieldEntry.getKey().equalsIgnoreCase("CONF")) {
+        
Assert.assertTrue(mapFieldEntry.getValue().contains("\"tez.task.resource.memory.mb\":\"5000\""));
+      }
+    }
+  }
 }
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMRCompactorOnTez.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMRCompactorOnTez.java
index 36154f49d4d..14197a5326d 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMRCompactorOnTez.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMRCompactorOnTez.java
@@ -42,7 +42,6 @@ public class TestMRCompactorOnTez extends CompactorOnTezTest {
     conf.setVar(HiveConf.ConfVars.COMPACTOR_JOB_QUEUE, 
CUSTOM_COMPACTION_QUEUE);
     conf.setBoolVar(HiveConf.ConfVars.HIVE_MR_COMPACTOR_GATHER_STATS, true);
     conf.setBoolVar(HiveConf.ConfVars.HIVESTATSAUTOGATHER, false);
-    String tmpFolder = folder.newFolder().getAbsolutePath();
     conf.setVar(HiveConf.ConfVars.HIVE_PROTO_EVENTS_BASE_PATH, tmpFolder);
 
     String dbName = "default";
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMmCompactorOnTez.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMmCompactorOnTez.java
index 841b6b85e42..e552f880da2 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMmCompactorOnTez.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestMmCompactorOnTez.java
@@ -61,11 +61,11 @@ public class TestMmCompactorOnTez extends 
CompactorOnTezTest {
 
   @Test public void testMmMinorCompactionNotPartitionedWithoutBuckets() throws 
Exception {
     conf.setVar(HiveConf.ConfVars.COMPACTOR_JOB_QUEUE, 
CUSTOM_COMPACTION_QUEUE);
-    String tmpFolder = folder.newFolder().getAbsolutePath();
     conf.setVar(HiveConf.ConfVars.HIVE_PROTO_EVENTS_BASE_PATH, tmpFolder);
 
     String dbName = "default";
     String tableName = "testMmMinorCompaction";
+    String dbTableName = dbName + "." + tableName;
     // Create test table
     TestDataProvider testDataProvider = new 
TestCrudCompactorOnTez.TestDataProvider();
     testDataProvider.createMmTable(tableName, false, false);
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorMR.java 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorMR.java
index 64a6e4f5d19..d83586d7ffa 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorMR.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorMR.java
@@ -36,7 +36,6 @@ import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hive.common.JavaUtils;
-import org.apache.hadoop.hive.common.StringableMap;
 import org.apache.hadoop.hive.common.ValidCompactorWriteIdList;
 import org.apache.hadoop.hive.common.ValidReadTxnList;
 import org.apache.hadoop.hive.common.ValidTxnList;
@@ -51,6 +50,7 @@ import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
 import org.apache.hadoop.hive.metastore.api.Table;
 import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
 import org.apache.hadoop.hive.metastore.txn.CompactionInfo;
+import org.apache.hadoop.hive.metastore.utils.StringableMap;
 import org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter;
 import org.apache.hadoop.hive.ql.io.AcidInputFormat;
 import org.apache.hadoop.hive.ql.io.AcidOutputFormat;
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorUtil.java 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorUtil.java
index 43781c1e932..7111b942563 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorUtil.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactorUtil.java
@@ -17,10 +17,10 @@
  */
 package org.apache.hadoop.hive.ql.txn.compactor;
 
-import org.apache.hadoop.hive.common.StringableMap;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.api.Table;
 import org.apache.hadoop.hive.metastore.txn.CompactionInfo;
+import org.apache.hadoop.hive.metastore.utils.StringableMap;
 
 import java.util.ArrayList;
 import java.util.Arrays;
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MajorQueryCompactor.java 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MajorQueryCompactor.java
index 3ff8cd6256b..a24fd32a22d 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MajorQueryCompactor.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MajorQueryCompactor.java
@@ -61,7 +61,8 @@ final class MajorQueryCompactor extends QueryCompactor {
     List<String> compactionQueries = getCompactionQueries(table, partition, 
tmpTableName);
     List<String> dropQueries = getDropQueries(tmpTableName);
     runCompactionQueries(conf, tmpTableName, storageDescriptor, writeIds, 
compactionInfo,
-        Lists.newArrayList(tmpTablePath), createQueries, compactionQueries, 
dropQueries);
+        Lists.newArrayList(tmpTablePath), createQueries, compactionQueries, 
dropQueries,
+            table.getParameters());
   }
 
   @Override
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MinorQueryCompactor.java 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MinorQueryCompactor.java
index c0bd4276ca0..63cb2ff93fb 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MinorQueryCompactor.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MinorQueryCompactor.java
@@ -69,7 +69,7 @@ final class MinorQueryCompactor extends QueryCompactor {
 
     runCompactionQueries(conf, tmpTableName, storageDescriptor, writeIds, 
compactionInfo,
         Lists.newArrayList(resultDeltaDir, resultDeleteDeltaDir), 
createQueries,
-        compactionQueries, dropQueries);
+        compactionQueries, dropQueries, table.getParameters());
   }
 
 
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMajorQueryCompactor.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMajorQueryCompactor.java
index 3ee2d0a3918..a6d3e3698e2 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMajorQueryCompactor.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMajorQueryCompactor.java
@@ -62,7 +62,8 @@ final class MmMajorQueryCompactor extends QueryCompactor {
     List<String> compactionQueries = getCompactionQueries(table, partition, 
tmpTableName);
     List<String> dropQueries = getDropQueries(tmpTableName);
     runCompactionQueries(driverConf, tmpTableName, storageDescriptor, 
writeIds, compactionInfo,
-        Lists.newArrayList(resultBaseDir), createTableQueries, 
compactionQueries, dropQueries);
+        Lists.newArrayList(resultBaseDir), createTableQueries, 
compactionQueries, dropQueries,
+            table.getParameters());
   }
 
   /**
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMinorQueryCompactor.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMinorQueryCompactor.java
index bb1fb66e69c..d9693642eae 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMinorQueryCompactor.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MmMinorQueryCompactor.java
@@ -61,7 +61,7 @@ final class MmMinorQueryCompactor extends QueryCompactor {
     List<String> compactionQueries = getCompactionQueries(tmpTableName, 
resultTmpTableName, table);
     List<String> dropQueries = getDropQueries(tmpTableName);
     runCompactionQueries(driverConf, tmpTableName, storageDescriptor, 
writeIds, compactionInfo,
-        Lists.newArrayList(resultDeltaDir), createTableQueries, 
compactionQueries, dropQueries);
+        Lists.newArrayList(resultDeltaDir), createTableQueries, 
compactionQueries, dropQueries, table.getParameters());
   }
 
   /**
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/QueryCompactor.java 
b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/QueryCompactor.java
index 81a80745e1c..758f451f9c5 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/QueryCompactor.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/QueryCompactor.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.hive.metastore.api.Partition;
 import org.apache.hadoop.hive.metastore.api.Table;
 import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
 import org.apache.hadoop.hive.metastore.txn.CompactionInfo;
+import org.apache.hadoop.hive.metastore.utils.StringableMap;
 import org.apache.hadoop.hive.ql.DriverUtils;
 import org.apache.hadoop.hive.ql.io.AcidDirectory;
 import org.apache.hadoop.hive.ql.io.AcidOutputFormat;
@@ -40,6 +41,9 @@ import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Stream;
 
 /**
  * Common interface for query based compactions.
@@ -47,6 +51,7 @@ import java.util.List;
 abstract class QueryCompactor {
 
   private static final Logger LOG = 
LoggerFactory.getLogger(QueryCompactor.class.getName());
+  private static final String COMPACTOR_PREFIX = "compactor.";
 
   /**
    * Start a query based compaction.
@@ -93,8 +98,8 @@ abstract class QueryCompactor {
    */
   void runCompactionQueries(HiveConf conf, String tmpTableName, 
StorageDescriptor storageDescriptor,
       ValidWriteIdList writeIds, CompactionInfo compactionInfo, List<Path> 
resultDirs,
-      List<String> createQueries, List<String> compactionQueries, List<String> 
dropQueries)
-      throws IOException {
+      List<String> createQueries, List<String> compactionQueries, List<String> 
dropQueries,
+      Map<String, String> tblProperties) throws IOException {
     String queueName = HiveConf.getVar(conf, 
HiveConf.ConfVars.COMPACTOR_JOB_QUEUE);
     if (queueName != null && queueName.length() > 0) {
       conf.set(TezConfiguration.TEZ_QUEUE_NAME, queueName);
@@ -102,6 +107,7 @@ abstract class QueryCompactor {
     Util.disableLlapCaching(conf);
     conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, true);
     conf.setBoolVar(HiveConf.ConfVars.HIVE_HDFS_ENCRYPTION_SHIM_CACHE_ON, 
false);
+    Util.overrideConfProps(conf, compactionInfo, tblProperties);
     String user = compactionInfo.runAs;
     SessionState sessionState = DriverUtils.setUpSessionState(conf, user, 
true);
     long compactorTxnId = CompactorMR.CompactorMap.getCompactorTxnId(conf);
@@ -272,5 +278,16 @@ abstract class QueryCompactor {
         fs.delete(dead, true);
       }
     }
+
+    static void overrideConfProps(HiveConf conf, CompactionInfo ci, 
Map<String, String> properties) {
+      Stream.of(properties, new StringableMap(ci.properties))
+              .filter(Objects::nonNull)
+              .flatMap(map -> map.entrySet().stream())
+              .filter(entry -> entry.getKey().startsWith(COMPACTOR_PREFIX))
+              .forEach(entry -> {
+                String property = 
entry.getKey().substring(COMPACTOR_PREFIX.length());
+                conf.set(property, entry.getValue());
+              });
+    }
   }
 }
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCompactorMRJobQueueConfiguration.java
 
b/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCompactorMRJobQueueConfiguration.java
index 17b20032508..8e773b590ad 100644
--- 
a/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCompactorMRJobQueueConfiguration.java
+++ 
b/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCompactorMRJobQueueConfiguration.java
@@ -17,7 +17,6 @@
  */
 package org.apache.hadoop.hive.ql.txn.compactor;
 
-import org.apache.hadoop.hive.common.StringableMap;
 import org.apache.hadoop.hive.common.ValidReaderWriteIdList;
 import org.apache.hadoop.hive.common.ValidWriteIdList;
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -26,6 +25,7 @@ import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
 import org.apache.hadoop.hive.metastore.api.Table;
 import org.apache.hadoop.hive.metastore.txn.CompactionInfo;
+import org.apache.hadoop.hive.metastore.utils.StringableMap;
 import org.apache.hadoop.mapred.JobConf;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.MethodSource;
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java 
b/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java
index f5b1389d3bf..94276ccccc3 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java
@@ -22,7 +22,6 @@ import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hive.common.FileUtils;
-import org.apache.hadoop.hive.common.StringableMap;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.HiveMetaStoreUtils;
 import org.apache.hadoop.hive.metastore.IMetaStoreClient;
@@ -41,6 +40,7 @@ import org.apache.hadoop.hive.metastore.api.TxnInfo;
 import org.apache.hadoop.hive.metastore.api.TxnState;
 import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
 import org.apache.hadoop.hive.metastore.txn.TxnStore;
+import org.apache.hadoop.hive.metastore.utils.StringableMap;
 import org.apache.hadoop.hive.ql.io.AcidUtils;
 import org.junit.After;
 import org.junit.Assert;
diff --git 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/StringableMap.java
 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/StringableMap.java
index d00c656f658..1bf6326fa98 100644
--- 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/StringableMap.java
+++ 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/StringableMap.java
@@ -39,16 +39,36 @@ public class StringableMap extends HashMap<String, String> {
     int numElements = Integer.parseInt(parts[0]);
     s = parts[1];
     for (int i = 0; i < numElements; i++) {
+      // Get the key String.
       parts = s.split(":", 2);
       int len = Integer.parseInt(parts[0]);
-      String key = null;
+      String key = "";     // Default is now an empty string.
+
       if (len > 0) key = parts[1].substring(0, len);
+        // Please check the toString() method of this class.
+        // null has -1 as length and empty String has 0.
+      else if (len < 0) {
+        key = null;
+        len = 0;         // Set 0 to 'len' for null-valued key
+        // since only len exists for null-valued key from the given String "s".
+      }
+
+      // Get the value String for the key
       parts = parts[1].substring(len).split(":", 2);
       len = Integer.parseInt(parts[0]);
-      String value = null;
+      String value = "";
+
       if (len > 0) value = parts[1].substring(0, len);
-      s = parts[1].substring(len);
+      else if (len < 0) {
+        value = null;
+        len = 0;        // Set 0 to 'len' since only len exists.
+      }
+
+      // Put the entry into the HashMap<String, String>.
       put(key, value);
+
+      // Move to the next substring to process.
+      s = parts[1].substring(len);
     }
   }
 
@@ -63,14 +83,21 @@ public class StringableMap extends HashMap<String, String> {
     buf.append(':');
     if (size() > 0) {
       for (Map.Entry<String, String> entry : entrySet()) {
-        int length = (entry.getKey() == null) ? 0 : entry.getKey().length();
-        buf.append(entry.getKey() == null ? 0 : length);
+        // Append the key String to the output StringBuilder.
+        // Note that null is saved as -1 in length, and that empty String as 0.
+        int length = (entry.getKey() == null) ? -1 : entry.getKey().length();
+        buf.append(length);
         buf.append(':');
         if (length > 0) buf.append(entry.getKey());
-        length = (entry.getValue() == null) ? 0 : entry.getValue().length();
+
+        // Append the value String to the output StringBuilder.
+        // Note that null is saved as -1 in length, and that empty String as 0.
+        length = (entry.getValue() == null) ? -1 : entry.getValue().length();
         buf.append(length);
         buf.append(':');
-        if (length > 0) buf.append(entry.getValue());
+        if (length > 0) {
+          buf.append(entry.getValue());
+        }
       }
     }
     return buf.toString();

Reply via email to