diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index c47b9fe..6a4e33f 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -93,6 +93,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.io.IOUtils; +import org.apache.hadoop.util.StringUtils; import org.apache.hive.beeline.cli.CliOptionsProcessor; import org.apache.hive.jdbc.Utils; @@ -672,6 +673,10 @@ int initArgsFromCliVars(String[] args) { getOpts().setScriptFile(commandLine.getOptionValue("f")); + if (commandLine.getOptionValues("i") != null) { + getOpts().setInitFile(StringUtils.join(" ", commandLine.getOptionValues("i"))); + } + dbName = commandLine.getOptionValue("database"); getOpts().setVerbose(Boolean.valueOf(commandLine.getOptionValue("verbose"))); getOpts().setSilent(Boolean.valueOf(commandLine.getOptionValue("slient"))); @@ -835,6 +840,8 @@ public int begin(String[] args, InputStream inputStream) throws IOException { getOpts().setShowHeader(false); getOpts().setOutputFormat("dsv"); getOpts().setDelimiterForDSV(' '); + + processInitFiles(opts.getInitFile()); } if (getOpts().getScriptFile() != null) { @@ -920,6 +927,25 @@ private int executeFile(String fileName) { } } + /** + * Only initial files specified by i option will be executed. The hiverc file will be processed by session manager. + * + * @param initFiles + * @throws IOException + */ + public void processInitFiles(String initFiles) throws IOException { + if (initFiles == null || initFiles.isEmpty()) { + return; + } + String[] files = initFiles.split(" "); + for (String initFile : files) { + int rc = executeFile(initFile); + if (rc != 0) { + System.exit(rc); + } + } + } + private int execute(ConsoleReader reader, boolean exitOnError) { String line; while (!exit) {