diff --git common/build.xml common/build.xml index 15a0e39..0d0665f 100755 --- common/build.xml +++ common/build.xml @@ -44,5 +44,30 @@ to call at top-level: ant deploy-contrib compile-core-test + + + + + + + + + + + + + + + + + + + Tests failed! + diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 897ec3c..dd5174c 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -614,8 +614,9 @@ public class HiveConf extends Configuration { private static synchronized URL getConfVarURL() { if (confVarURL == null) { try { + Configuration conf = new Configuration(); File confVarFile = File.createTempFile("hive-default-", ".xml"); - Configuration conf = new Configuration(false); + confVarFile.deleteOnExit(); applyDefaultConfVars(conf); @@ -772,7 +773,7 @@ public class HiveConf extends Configuration { // preserve the original configuration origProp = getAllProperties(); - // Overlay the default ConfVars + // Use ConfVars to set properties not already set by Hadoop addResource(getConfVarURL()); // Overlay hive-site.xml if it exists @@ -814,6 +815,10 @@ public class HiveConf extends Configuration { private static void applyDefaultConfVars(Configuration conf) { for (ConfVars var : ConfVars.values()) { + if (conf.get(var.varname) != null) { + // Don't overwrite any properties already set by Hadoop + continue; + } if (String.class.equals(var.valClass)) { conf.set(var.varname, var.defaultVal); } else if (Integer.class.equals(var.valClass)) { diff --git common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java index 73c788c..32c9f84 100644 --- common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java +++ common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java @@ -19,12 +19,15 @@ package org.apache.hadoop.hive.conf; import junit.framework.TestCase; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; /** * TestHiveConf * + * Test cases for HiveConf. Loads configuration files located + * in common/src/test/resources. */ public class TestHiveConf extends TestCase { @@ -51,4 +54,18 @@ public class TestHiveConf extends TestCase { // Test Hive conf property variable substitution in hive-site.xml assertEquals(conf.get("hive.exec.default.partition.name"), conf.get("test.var.hiveconf.property")); } + + public void testHadoopConfProperties() throws Exception { + Configuration conf = new Configuration(); + HiveConf hiveConf = new HiveConf(); + + // Verify that Configuration is picking up the right core-site.xml file + assertEquals("core-site.xml", conf.get("fs.default.name")); + + // Verify that core-site.xml and ConfVars have different values for fs.default.name + assertTrue(!conf.get("fs.default.name").equals(HiveConf.ConfVars.HADOOPFS.defaultVal)); + + // Verify that ConfVars are not able to override properties defined in core-site.xml + assertEquals("core-site.xml", hiveConf.get("fs.default.name")); + } } diff --git common/src/test/resources/core-site.xml common/src/test/resources/core-site.xml new file mode 100644 index 0000000..ffe9747 --- /dev/null +++ common/src/test/resources/core-site.xml @@ -0,0 +1,27 @@ + + + + + + + + + fs.default.name + core-site.xml + + diff --git common/src/test/resources/hive-site.xml common/src/test/resources/hive-site.xml index d4d72a1..508d134 100644 --- common/src/test/resources/hive-site.xml +++ common/src/test/resources/hive-site.xml @@ -17,6 +17,8 @@ limitations under the License. --> + +