public
HiveHistoryImpl(SessionState ss) {
try
{
console =
new
LogHelper(LOG);
if
(ss.getConf().getBoolVar(HiveConf.ConfVars.HIVE_USE_CUSTOM_PROXY)){
LOG.warn(
"user custom proxy,gen history log file"
);
proxyUser = ss.getConf().getVar(HiveConf.ConfVars.HIVE_CUSTOM_PROXY_USER);
if
((
""
).equals(proxyUser)||proxyUser ==
null
||(
"hdfs"
).equals(proxyUser)){
console.printError(
"gen history file,use proxy,but proxy user is "
+ proxyUser);
return
;
}
conf_file_loc = System.getProperty(
"java.io.tmpdir"
) + File.separator + proxyUser;
}
else
{
conf_file_loc = ss.getConf().getVar(
HiveConf.ConfVars.HIVEHISTORYFILELOC);
}
LOG.warn(
"user history log dir is "
+ conf_file_loc);
if
((conf_file_loc ==
null
) || conf_file_loc.length() ==
0
) {
console.printError(
"No history file location given"
);
return
;
}
File histDir =
new
File(conf_file_loc);
if
(!histDir.exists()) {
if
(!histDir.mkdirs()) {
console.printError(
"Unable to create log directory "
+ conf_file_loc);
return
;
}
}
do
{
histFileName = conf_file_loc + File.separator +
"hive_job_log_"
+ ss.getSessionId() +
"_"
+ Math.abs(randGen.nextInt()) +
".txt"
;
}
while
(!
new
File(histFileName).createNewFile());
console.printInfo(
"Hive history file="
+ histFileName);
histStream =
new
PrintWriter(histFileName);
HashMap<String, String> hm =
new
HashMap<String, String>();
hm.put(Keys.SESSION_ID.name(), ss.getSessionId());
log(RecordTypes.SessionStart, hm);
}
catch
(IOException e) {
console.printError(
"FAILED: Failed to open Query Log : "
+ histFileName
+
" "
+ e.getMessage(),
"\n"
+ org.apache.hadoop.util.StringUtils.stringifyException(e));
}
}