You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by se...@apache.org on 2015/09/28 21:10:14 UTC
[12/43] hive git commit: HIVE-11191: Beeline-cli: support
hive.cli.errors.ignore in new CLI(Ferdinand Xu, reviewed by Xuefu Zhang)
HIVE-11191: Beeline-cli: support hive.cli.errors.ignore in new CLI(Ferdinand Xu, reviewed by Xuefu Zhang)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/eccfdf0e
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/eccfdf0e
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/eccfdf0e
Branch: refs/heads/llap
Commit: eccfdf0ed7f1847ba1c0e3ad5aee0f2a6c9857c8
Parents: f589e2c
Author: Ferdinand Xu <ch...@intel.com>
Authored: Thu Jul 9 20:58:14 2015 -0400
Committer: Ferdinand Xu <ch...@intel.com>
Committed: Thu Jul 9 20:58:14 2015 -0400
----------------------------------------------------------------------
.../java/org/apache/hive/beeline/BeeLine.java | 37 ++++++++++++++++----
.../org/apache/hive/beeline/BeeLineOpts.java | 18 ++++++++++
.../java/org/apache/hive/beeline/Commands.java | 36 ++++++++++++++-----
.../apache/hive/beeline/cli/TestHiveCli.java | 3 +-
4 files changed, 77 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/eccfdf0e/beeline/src/java/org/apache/hive/beeline/BeeLine.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
index c4dbcd4..7c53997 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -87,7 +87,6 @@ import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
-import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.io.IOUtils;
import org.apache.hive.beeline.cli.CliOptionsProcessor;
import org.apache.hive.jdbc.Utils;
@@ -406,10 +405,8 @@ public class BeeLine implements Closeable {
String getApplicationTitle() {
Package pack = BeeLine.class.getPackage();
- return loc("app-introduction", new Object[] {
- "Beeline",
- pack.getImplementationVersion() == null ? "???"
- : pack.getImplementationVersion(),
+ return loc("app-introduction", new Object[] { "Beeline",
+ pack.getImplementationVersion() == null ? "???" : pack.getImplementationVersion(),
"Apache Hive",
// getManifestAttribute ("Specification-Title"),
// getManifestAttribute ("Implementation-Version"),
@@ -826,8 +823,10 @@ public class BeeLine implements Closeable {
} else {
int code = initArgsFromCliVars(args);
defaultConnect(false);
- if (code != 0)
+ if (code != 0){
return code;
+ }
+ getOpts().updateBeeLineOptsFromConf();
}
if (getOpts().getScriptFile() != null) {
@@ -1077,8 +1076,32 @@ public class BeeLine implements Closeable {
return cmdMap.values().iterator().next()
.execute(line);
} else {
- return commands.sql(line, getOpts().getEntireLineAsCommand());
+ boolean needsUpdate = isConfNeedsUpdate(line);
+ boolean res = commands.sql(line, getOpts().getEntireLineAsCommand());
+ if (needsUpdate) {
+ getOpts().setHiveConf(getCommands().getHiveConf(true));
+ }
+ return res;
+ }
+ }
+
+ /**
+ * Update the configurations for the CLI mode in the client side
+ *
+ * @param line
+ */
+ private boolean isConfNeedsUpdate(String line) {
+ if (isBeeLine) {
+ return false;
+ }
+ String[] cmds = line.split(";");
+ boolean containsSetCMD = false;
+ for (String s : cmds) {
+ if (s.toLowerCase().startsWith("set")) {
+ return true;
+ }
}
+ return containsSetCMD;
}
/**
http://git-wip-us.apache.org/repos/asf/hive/blob/eccfdf0e/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
index c1ec82a..894f74f 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
@@ -42,6 +42,7 @@ import jline.Terminal;
import jline.TerminalFactory;
import jline.console.completer.Completer;
import jline.console.completer.StringsCompleter;
+import org.apache.hadoop.hive.conf.HiveConf;
class BeeLineOpts implements Completer {
public static final int DEFAULT_MAX_WIDTH = 80;
@@ -78,6 +79,8 @@ class BeeLineOpts implements Completer {
int timeout = -1;
private String isolation = DEFAULT_ISOLATION_LEVEL;
private String outputFormat = "table";
+ // This configuration is used only for client side configuration.
+ private HiveConf conf;
private boolean trimScripts = true;
private boolean allowMultiLineCommand = true;
@@ -219,6 +222,21 @@ class BeeLineOpts implements Completer {
loadProperties(p);
}
+ /**
+ * Update the options after connection is established in CLI mode.
+ */
+ public void updateBeeLineOptsFromConf() {
+ if (!beeLine.isBeeLine()) {
+ if (conf == null) {
+ conf = beeLine.getCommands().getHiveConf(true);
+ }
+ setForce(HiveConf.getBoolVar(conf, HiveConf.ConfVars.CLIIGNOREERRORS));
+ }
+ }
+
+ public void setHiveConf(HiveConf conf) {
+ this.conf = conf;
+ }
public void loadProperties(Properties props) {
for (Object element : props.keySet()) {
http://git-wip-us.apache.org/repos/asf/hive/blob/eccfdf0e/beeline/src/java/org/apache/hive/beeline/Commands.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/Commands.java b/beeline/src/java/org/apache/hive/beeline/Commands.java
index d490273..b07388a 100644
--- a/beeline/src/java/org/apache/hive/beeline/Commands.java
+++ b/beeline/src/java/org/apache/hive/beeline/Commands.java
@@ -721,7 +721,7 @@ public class Commands {
*/
private Map<String, String> getHiveVariables() {
Map<String, String> result = new HashMap<>();
- BufferedRows rows = getConfInternal();
+ BufferedRows rows = getConfInternal(true);
while (rows.hasNext()) {
Rows.Row row = (Rows.Row) rows.next();
if (!row.isMeta) {
@@ -731,27 +731,45 @@ public class Commands {
return result;
}
- private HiveConf getHiveConf() {
+ /**
+ * This method should only be used in CLI mode.
+ *
+ * @return the hive configuration from server side
+ */
+ public HiveConf getHiveConf(boolean call) {
HiveConf conf = new HiveConf();
- BufferedRows rows = getConfInternal();
- while (rows.hasNext()) {
+ BufferedRows rows = getConfInternal(call);
+ while (rows != null && rows.hasNext()) {
addConf((Rows.Row) rows.next(), conf);
}
return conf;
}
- private BufferedRows getConfInternal() {
+ /**
+ * Use call statement to retrieve the configurations for substitution and sql for the substitution.
+ *
+ * @param call
+ * @return
+ */
+ private BufferedRows getConfInternal(boolean call) {
Statement stmnt = null;
BufferedRows rows = null;
try {
- stmnt = beeLine.createStatement();
- boolean hasResults = stmnt.execute("set");
+ boolean hasResults;
+ if (call) {
+ stmnt = beeLine.getDatabaseConnection().getConnection().prepareCall("set");
+ hasResults = ((CallableStatement) stmnt).execute();
+ } else {
+ stmnt = beeLine.createStatement();
+ hasResults = stmnt.execute("set");
+ }
if (hasResults) {
ResultSet rs = stmnt.getResultSet();
rows = new BufferedRows(beeLine, rs);
}
} catch (SQLException e) {
beeLine.error(e);
+ } finally {
if (stmnt != null) {
try {
stmnt.close();
@@ -802,7 +820,7 @@ public class Commands {
String[] tokens = tokenizeCmd(cmd);
String cmd_1 = getFirstCmd(cmd, tokens[0].length());
- cmd_1 = substituteVariables(getHiveConf(), cmd_1);
+ cmd_1 = substituteVariables(getHiveConf(false), cmd_1);
File sourceFile = new File(cmd_1);
if (!sourceFile.isFile()) {
return false;
@@ -1020,7 +1038,7 @@ public class Commands {
}
line = line.substring("sh".length()).trim();
- line = substituteVariables(getHiveConf(), line.trim());
+ line = substituteVariables(getHiveConf(false), line.trim());
try {
ShellCmdExecutor executor = new ShellCmdExecutor(line, beeLine.getOutputStream(),
http://git-wip-us.apache.org/repos/asf/hive/blob/eccfdf0e/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
----------------------------------------------------------------------
diff --git a/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java b/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
index ff8ab17..fa94c89 100644
--- a/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
+++ b/beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
@@ -78,7 +78,8 @@ public class TestHiveCli {
int retCode) {
executeCMD(options, CMD, retCode);
String output = os.toString();
- Assert.assertTrue(output.contains(keywords));
+ Assert.assertTrue("The expected keyword doesn't occur in the output: " + output,
+ output.contains(keywords));
}
@Test