diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 056f2d78346b6b306d34dfb610e3a7fed4ca68aa..d7fa10b9b5c89849d18770931b932ade2ec884e9 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hive.conf; import com.google.common.base.Joiner; +import com.google.common.collect.Iterables; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.common.FileUtils; @@ -3759,9 +3760,9 @@ public void verifyAndSet(String name, String value) throws IllegalArgumentExcept + "It is not in list of params that are allowed to be modified at runtime"); } } - if (restrictList.contains(name)) { + if (Iterables.any(restrictList, restrictedVar -> restrictedVar.startsWith(name))) { throw new IllegalArgumentException("Cannot modify " + name + " at runtime. It is in the list" - + " of parameters that can't be modified at runtime"); + + " of parameters that can't be modified at runtime or is prefixed by a restricted variable"); } String oldValue = name != null ? get(name) : null; if (name == null || value == null || !value.equals(oldValue)) { diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConfUtil.java common/src/java/org/apache/hadoop/hive/conf/HiveConfUtil.java index 9084fed9fa5121285709874923b3e03e887cb20d..f4300b0fae0c3116817850bbac27c30c69c7b6b0 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConfUtil.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConfUtil.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hive.conf; +import com.google.common.collect.Iterables; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -92,11 +93,20 @@ public static StringBuilder dumpConfig(HiveConf conf) { * @param hiddenSet The values to strip */ public static void stripConfigurations(Configuration conf, Set hiddenSet) { - for (String name : hiddenSet) { - if (conf.get(name) != null) { - conf.set(name, StringUtils.EMPTY); - } - } + + // Find all configurations where the key contains any string from hiddenSet + Iterable> matching = + Iterables.filter(conf, confEntry -> { + for (String name : hiddenSet) { + if (confEntry.getKey().startsWith(name)) { + return true; + } + } + return false; + }); + + // Remove the value of every key found matching + matching.forEach(entry -> conf.set(entry.getKey(), StringUtils.EMPTY)); } /** diff --git common/src/test/org/apache/hadoop/hive/conf/TestHiveConfRestrictList.java common/src/test/org/apache/hadoop/hive/conf/TestHiveConfRestrictList.java index 980fa761541d72a0b37bc5d687e1fbc4551b5282..adf3cfb1661385b4ec192cf451ddf37709ceee22 100644 --- common/src/test/org/apache/hadoop/hive/conf/TestHiveConfRestrictList.java +++ common/src/test/org/apache/hadoop/hive/conf/TestHiveConfRestrictList.java @@ -41,7 +41,17 @@ protected void setUp() throws Exception { @Test public void testRestriction() throws Exception { verifyRestriction(ConfVars.HIVETESTMODEPREFIX.varname, "foo"); - conf.verifyAndSet(ConfVars.HIVETESTMODE.varname, "false"); + conf.verifyAndSet(ConfVars.HIVE_AM_SPLIT_GENERATION.varname, "false"); + } + + /** + * Test that configs in restrict list can't be changed + * @throws Exception + */ + @Test + public void testMultipleRestrictions() throws Exception { + verifyRestriction(ConfVars.HIVETESTMODEPREFIX.varname, "foo"); + verifyRestriction(ConfVars.HIVETESTMODE.varname, "false"); } /** diff --git common/src/test/org/apache/hadoop/hive/conf/TestHiveConfUtil.java common/src/test/org/apache/hadoop/hive/conf/TestHiveConfUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..e326b635c8dd3e67a13cdd1dbea7c2410ebdeadd --- /dev/null +++ common/src/test/org/apache/hadoop/hive/conf/TestHiveConfUtil.java @@ -0,0 +1,68 @@ +/** + * 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.conf; + +import com.google.common.collect.Sets; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * TestHiveConfUtil + * + */ +public class TestHiveConfUtil { + + private HiveConf conf = new HiveConf(); + + @Before + public void init() { + conf.setBoolean("dummyBoolean", true); + conf.set("dummy", "aaa"); + conf.set("dummy2", "aaa"); + conf.set("3dummy", "aaa"); + } + + @Test + public void testHideNonStringVar() throws Exception { + Assert.assertTrue(conf.getBoolean("dummyBoolean", false)); + Assert.assertEquals("true", conf.get("dummyBoolean")); + HiveConfUtil.stripConfigurations(conf, Sets.newHashSet("dummyBoolean")); + Assert.assertFalse(conf.getBoolean("dummyBoolean", false)); + Assert.assertEquals("", conf.get("dummyBoolean")); + } + + @Test + public void testHideStringVar() throws Exception { + Assert.assertEquals("aaa", conf.get("dummy")); + HiveConfUtil.stripConfigurations(conf, Sets.newHashSet("dummy")); + Assert.assertEquals("", conf.get("dummy")); + } + + @Test + public void testHideMultipleVars() throws Exception { + Assert.assertEquals("aaa", conf.get("dummy")); + Assert.assertEquals("aaa", conf.get("dummy2")); + Assert.assertEquals("aaa", conf.get("3dummy")); + HiveConfUtil.stripConfigurations(conf, Sets.newHashSet("dummy")); + Assert.assertEquals("", conf.get("dummy")); + Assert.assertEquals("", conf.get("dummy2")); + Assert.assertEquals("aaa", conf.get("3dummy")); + } + +}