hiveCmd = hiveCmd.toLowerCase().trim();
if(hiveCmd.startsWith("select"))
returnResult = true;
IStreamHandler statusHandler = StreamHandlerFactory.createStatusHandler(statusLocation);
IStreamHandler resultHandler = null;
if(returnResult){
if(storeResultToFile){
resultHandler = StreamHandlerFactory.createFileResultHandler(resultLocation);
}
else{
resultHandler = StreamHandlerFactory.createMemResultHandler();
hiveCmd = joinString(hiveCmd, " limit ", ""+limit);
}
resultHandler.setLimit(limit);
}
if(!storeResultToFile && !hiveCmd.contains(" limit ")){
hiveCmd = joinString(hiveCmd, " limit ", ""+limit);
}
if(!hiveCmd.endsWith(";")){
hiveCmd += ";";
}
String cmd = joinString("sudo -u ", username," sh -c \"source /etc/profile;" ,HIVE_CMD, " -e \\\"", hiveCmd, "\\\"");
//add hiveconf
for(String hiveConf: s_hiveConfigSet){
cmd = joinString(cmd, " -hiveconf ", hiveConf, " \"");
}
//execute cmd
int exitCode = -1;
try {
exitCode = ShellCmdExecutor.getInstance().execute(cmd, key, resultHandler, statusHandler);
} catch (ShellCmdExecException e) {
s_logger.error("Exceptions occurs in executing hive command!", e);
return null;
}
if(exitCode != 0){
s_logger.error("Hive Command is NOT executed successfully! The exit code of hive command is " + exitCode);
return null;
}
return resultHandler.getResult();
}