You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ke...@apache.org on 2012/11/20 10:03:27 UTC
svn commit: r1411592 - in
/hive/trunk/common/src/java/org/apache/hadoop/hive/conf: HiveConf.java
LoopingByteArrayInputStream.java
Author: kevinwilfong
Date: Tue Nov 20 09:03:26 2012
New Revision: 1411592
URL: http://svn.apache.org/viewvc?rev=1411592&view=rev
Log:
Remove extra files accidentally committed with HIVE-3679. (kevinwilfong)
Removed:
hive/trunk/common/src/java/org/apache/hadoop/hive/conf/LoopingByteArrayInputStream.java
Modified:
hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1411592&r1=1411591&r2=1411592&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Tue Nov 20 09:03:26 2012
@@ -18,10 +18,9 @@
package org.apache.hadoop.hive.conf;
-import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.util.HashMap;
@@ -53,6 +52,7 @@ public class HiveConf extends Configurat
protected String auxJars;
private static final Log l4j = LogFactory.getLog(HiveConf.class);
private static URL hiveSiteURL = null;
+ private static URL confVarURL = null;
private static final Map<String, ConfVars> vars = new HashMap<String, ConfVars>();
@@ -789,34 +789,35 @@ public class HiveConf extends Configurat
}
/**
- * Writes the default ConfVars out to a byte array and returns an input
- * stream wrapping that byte array.
- *
+ * Writes the default ConfVars out to a temporary File and returns
+ * a URL pointing to the temporary file.
* We need this in order to initialize the ConfVar properties
- * in the underling Configuration object using the addResource(InputStream)
+ * in the underling Configuration object using the addResource(URL)
* method.
*
- * It is important to use a LoopingByteArrayInputStream because it turns out
- * addResource(InputStream) is broken since Configuration tries to read the
- * entire contents of the same InputStream repeatedly without resetting it.
- * LoopingByteArrayInputStream has special logic to handle this.
+ * Using Configuration.addResource(InputStream) would be a preferable
+ * approach, but it turns out that method is broken since Configuration
+ * tries to read the entire contents of the same InputStream repeatedly.
*/
- private static synchronized InputStream getConfVarInputStream() {
- byte[] confVarByteArray;
- try {
- Configuration conf = new Configuration();
-
- applyDefaultNonNullConfVars(conf);
-
- ByteArrayOutputStream confVarBaos = new ByteArrayOutputStream();
- conf.writeXml(confVarBaos);
- confVarByteArray = confVarBaos.toByteArray();
- } catch (Exception e) {
- // We're pretty screwed if we can't load the default conf vars
- throw new RuntimeException("Failed to initialize default Hive configuration variables!", e);
+ private static synchronized URL getConfVarURL() {
+ if (confVarURL == null) {
+ try {
+ Configuration conf = new Configuration();
+ File confVarFile = File.createTempFile("hive-default-", ".xml");
+ confVarFile.deleteOnExit();
+
+ applyDefaultNonNullConfVars(conf);
+
+ FileOutputStream fout = new FileOutputStream(confVarFile);
+ conf.writeXml(fout);
+ fout.close();
+ confVarURL = confVarFile.toURI().toURL();
+ } catch (Exception e) {
+ // We're pretty screwed if we can't load the default conf vars
+ throw new RuntimeException("Failed to initialize default Hive configuration variables!", e);
+ }
}
-
- return new LoopingByteArrayInputStream(confVarByteArray);
+ return confVarURL;
}
public static int getIntVar(Configuration conf, ConfVars var) {
@@ -981,7 +982,7 @@ public class HiveConf extends Configurat
origProp = getAllProperties();
// Overlay the ConfVars. Note that this ignores ConfVars with null values
- addResource(getConfVarInputStream());
+ addResource(getConfVarURL());
// Overlay hive-site.xml if it exists
if (hiveSiteURL != null) {