public int processFile(String fileName) throws IOException { BufferedReader bufferedReader = null; try { bufferedReader = loadFile(fileName); return (processReader(bufferedReader)); } finally { IOUtils.closeStream(bufferedReader); } }
/** * execute the buffered reader which stores the commands * @param reader the buffered reader * @return the return code of the execution result * @throws IOException */ protected int processReader(BufferedReader reader) throws IOException { String line; StringBuilder qsb = new StringBuilder(); while ((line = reader.readLine()) != null) { if (!line.startsWith("--")) { qsb.append(line); } } return processLine(qsb.toString()); }
/** * process the Hive command by lines * @param line contains a legal Hive command * @return the return code of the execution result */ protected int processLine(String line) { int lastRet = 0, ret = 0; String command = ""; for (String oneCmd : line.split(";")) { if (StringUtils.indexOf(oneCmd, "\\") != -1) { command += StringUtils.join(oneCmd.split("\\\\")); } else { command += oneCmd; } if (StringUtils.isBlank(command)) { continue; } ret = processCmd(command); command = ""; lastRet = ret; if (ret != 0) { return ret; } } return lastRet; }
public boolean sh(String line) { if (line == null || line.length() == 0) { return false; } if (!line.startsWith("sh")) { return false; } line = line.substring("sh".length()).trim(); if (!beeLine.isBeeLine()) line = substituteVariables(getHiveConf(false), line.trim()); try { ShellCmdExecutor executor = new ShellCmdExecutor(line, beeLine.getOutputStream(), beeLine.getErrorStream()); int ret = executor.execute(); if (ret != 0) { beeLine.output("Command failed with exit code = " + ret); return false; } return true; } catch (Exception e) { beeLine.error("Exception raised from Shell command " + e); return false; } }
/** * Add the hiveconf properties to the Java system properties, override * anything therein. * * @return a copy of the properties specified in hiveconf */ public Properties addHiveconfToSystemProperties() { Properties confProps = commandLine.getOptionProperties("hiveconf"); for (String propKey : confProps.stringPropertyNames()) { if (verbose) { System.err.println( "hiveconf: " + propKey + "=" + confProps.getProperty(propKey)); } if (propKey.equalsIgnoreCase("hive.root.logger")) { splitAndSetLogger(propKey, confProps); } else { System.setProperty(propKey, confProps.getProperty(propKey)); } } return confProps; }
private void processGlobalInitFile() { IHiveFileProcessor processor = new GlobalHivercFileProcessor(); try { String hiverc = sessionConf.getVar(ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION); if (hiverc != null) { File hivercFile = new File(hiverc); if (hivercFile.isDirectory()) { hivercFile = new File(hivercFile, SessionManager.HIVERCFILE); } if (hivercFile.isFile()) { LOG.info("Running global init file: " + hivercFile); int rc = processor.processFile(hivercFile.getAbsolutePath()); if (rc != 0) { LOG.error("Failed on initializing global .hiverc file"); } } else { LOG.debug("Global init file " + hivercFile + " does not exist"); } } } catch (IOException e) { LOG.warn("Failed on initializing global .hiverc file", e); } }
/** * Parse the arguments. * @param args */ public void parse(String[] args) { try { commandLine = new GnuParser().parse(OPTIONS, args); if (commandLine.hasOption('h')) { printUsage(); System.exit(1); } if (commandLine.hasOption('v')) { verbose = true; } } catch (ParseException e) { System.err.println(e.getMessage()); printUsage(); System.exit(1); } }
value = EscapeCRLFHelper.escapeCRLF(value);
ShellCmdExecutor executor = new ShellCmdExecutor(shell_cmd, ss.out, ss.err); ret = executor.execute(); if (ret != 0) { console.printError("Command failed with exit code = " + ret);
public int processFile(String fileName) throws IOException { BufferedReader bufferedReader = null; try { bufferedReader = loadFile(fileName); return (processReader(bufferedReader)); } finally { IOUtils.closeStream(bufferedReader); } }
if (propKey.equalsIgnoreCase("hive.root.logger")) { CommonCliOptions.splitAndSetLogger(propKey, confProps); } else { System.setProperty(propKey, confProps.getProperty(propKey));
/** * execute the buffered reader which stores the commands * @param reader the buffered reader * @return the return code of the execution result * @throws IOException */ protected int processReader(BufferedReader reader) throws IOException { String line; StringBuilder qsb = new StringBuilder(); while ((line = reader.readLine()) != null) { if (!line.startsWith("--")) { qsb.append(line); } } return processLine(qsb.toString()); }
/** * process the Hive command by lines * @param line contains a legal Hive command * @return the return code of the execution result */ protected int processLine(String line) { int lastRet = 0, ret = 0; String command = ""; for (String oneCmd : line.split(";")) { if (StringUtils.indexOf(oneCmd, "\\") != -1) { command += StringUtils.join(oneCmd.split("\\\\")); } else { command += oneCmd; } if (StringUtils.isBlank(command)) { continue; } ret = processCmd(command); command = ""; lastRet = ret; if (ret != 0) { return ret; } } return lastRet; }
for (String r : res) { if (escapeCRLF) { r = EscapeCRLFHelper.escapeCRLF(r);
public boolean sh(String line) { if (line == null || line.length() == 0) { return false; } if (!line.startsWith("sh")) { return false; } line = line.substring("sh".length()).trim(); // Support variable substitution. HIVE-6791. // line = new VariableSubstitution().substitute(new HiveConf(BeeLine.class), line.trim()); try { ShellCmdExecutor executor = new ShellCmdExecutor(line, beeLine.getOutputStream(), beeLine.getErrorStream()); int ret = executor.execute(); if (ret != 0) { beeLine.output("Command failed with exit code = " + ret); return false; } return true; } catch (Exception e) { beeLine.error("Exception raised from Shell command " + e); beeLine.error(e); return false; } }
public int processFile(String fileName) throws IOException { BufferedReader bufferedReader = null; try { bufferedReader = loadFile(fileName); return (processReader(bufferedReader)); } finally { IOUtils.closeStream(bufferedReader); } }
public boolean process_stage1(String[] argv) { try { commandLine = new GnuParser().parse(options, argv); Properties confProps = commandLine.getOptionProperties("hiveconf"); for (String propKey : confProps.stringPropertyNames()) { // with HIVE-11304, hive.root.logger cannot have both logger name and log level. // if we still see it, split logger and level separately for hive.root.logger // and hive.log.level respectively if (propKey.equalsIgnoreCase("hive.root.logger")) { CommonCliOptions.splitAndSetLogger(propKey, confProps); } else { System.setProperty(propKey, confProps.getProperty(propKey)); } } Properties hiveVars = commandLine.getOptionProperties("define"); for (String propKey : hiveVars.stringPropertyNames()) { hiveVariables.put(propKey, hiveVars.getProperty(propKey)); } Properties hiveVars2 = commandLine.getOptionProperties("hivevar"); for (String propKey : hiveVars2.stringPropertyNames()) { hiveVariables.put(propKey, hiveVars2.getProperty(propKey)); } } catch (ParseException e) { System.err.println(e.getMessage()); printUsage(); return false; } return true; }
/** * execute the buffered reader which stores the commands * @param reader the buffered reader * @return the return code of the execution result * @throws IOException */ protected int processReader(BufferedReader reader) throws IOException { String line; StringBuilder qsb = new StringBuilder(); while ((line = reader.readLine()) != null) { if (!line.startsWith("--")) { qsb.append(line); } } return processLine(qsb.toString()); }
/** * process the Hive command by lines * @param line contains a legal Hive command * @return the return code of the execution result */ protected int processLine(String line) { int lastRet = 0, ret = 0; String command = ""; for (String oneCmd : line.split(";")) { if (StringUtils.indexOf(oneCmd, "\\") != -1) { command += StringUtils.join(oneCmd.split("\\\\")); } else { command += oneCmd; } if (StringUtils.isBlank(command)) { continue; } ret = processCmd(command); command = ""; lastRet = ret; if (ret != 0) { return ret; } } return lastRet; }
public boolean sh(String line) { if (line == null || line.length() == 0) { return false; } if (!line.startsWith("sh")) { return false; } line = line.substring("sh".length()).trim(); // Support variable substitution. HIVE-6791. // line = new VariableSubstitution().substitute(new HiveConf(BeeLine.class), line.trim()); try { ShellCmdExecutor executor = new ShellCmdExecutor(line, beeLine.getOutputStream(), beeLine.getErrorStream()); int ret = executor.execute(); if (ret != 0) { beeLine.output("Command failed with exit code = " + ret); return false; } return true; } catch (Exception e) { beeLine.error("Exception raised from Shell command " + e); beeLine.error(e); return false; } }