You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2017/01/17 06:36:18 UTC
hive git commit: fix arglist logging in schematool (Anishek Agarwal
via Thejas Nair)
Repository: hive
Updated Branches:
refs/heads/master 566788696 -> ea87e0f26
fix arglist logging in schematool (Anishek Agarwal via Thejas Nair)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/ea87e0f2
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/ea87e0f2
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/ea87e0f2
Branch: refs/heads/master
Commit: ea87e0f26112f0cdbe2fa06e3090fb7b49d81569
Parents: 5667886
Author: Anishek Agarwal <an...@gmail.com>
Authored: Mon Jan 16 22:36:09 2017 -0800
Committer: Thejas M Nair <th...@hortonworks.com>
Committed: Mon Jan 16 22:36:09 2017 -0800
----------------------------------------------------------------------
beeline/pom.xml | 12 ++-
.../org/apache/hive/beeline/HiveSchemaTool.java | 80 +++++++++++---------
pom.xml | 11 ++-
3 files changed, 65 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/ea87e0f2/beeline/pom.xml
----------------------------------------------------------------------
diff --git a/beeline/pom.xml b/beeline/pom.xml
index 5503add..58ca92e 100644
--- a/beeline/pom.xml
+++ b/beeline/pom.xml
@@ -29,6 +29,7 @@
<properties>
<hive.path.to.root>..</hive.path.to.root>
+ <powermock.version>1.6.6</powermock.version>
</properties>
<dependencies>
@@ -119,8 +120,15 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/hive/blob/ea87e0f2/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
index a981bce..ea58776 100644
--- a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
+++ b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
@@ -815,38 +815,10 @@ public class HiveSchemaTool {
// Generate the beeline args per hive conf and execute the given script
public void runBeeLine(String sqlScriptFile) throws IOException {
- List<String> argList = new ArrayList<String>();
- argList.add("-u");
- argList.add(HiveSchemaHelper.getValidConfVar(
- ConfVars.METASTORECONNECTURLKEY, hiveConf));
- argList.add("-d");
- argList.add(HiveSchemaHelper.getValidConfVar(
- ConfVars.METASTORE_CONNECTION_DRIVER, hiveConf));
- argList.add("-n");
- argList.add(userName);
- argList.add("-p");
- argList.add(passWord);
- argList.add("-f");
- argList.add(sqlScriptFile);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Going to invoke file that contains:");
- BufferedReader reader = new BufferedReader(new FileReader(sqlScriptFile));
- try {
- String line;
- while ((line = reader.readLine()) != null) {
- LOG.debug("script: " + line);
- }
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
+ CommandBuilder builder = new CommandBuilder(hiveConf, userName, passWord, sqlScriptFile);
// run the script using Beeline
- BeeLine beeLine = new BeeLine();
- try {
+ try (BeeLine beeLine = new BeeLine()) {
if (!verbose) {
beeLine.setOutputStream(new PrintStream(new NullOutputStream()));
beeLine.getOpts().setSilent(true);
@@ -856,13 +828,53 @@ public class HiveSchemaTool {
// We can be pretty sure that an entire line can be processed as a single command since
// we always add a line separator at the end while calling dbCommandParser.buildCommand.
beeLine.getOpts().setEntireLineAsCommand(true);
- LOG.debug("Going to run command <" + StringUtils.join(argList, " ") + ">");
- int status = beeLine.begin(argList.toArray(new String[0]), null);
+ LOG.debug("Going to run command <" + builder.buildToLog() + ">");
+ int status = beeLine.begin(builder.buildToRun(), null);
if (status != 0) {
throw new IOException("Schema script failed, errorcode " + status);
}
- } finally {
- beeLine.close();
+ }
+ }
+
+ static class CommandBuilder {
+ private final HiveConf hiveConf;
+ private final String userName;
+ private final String password;
+ private final String sqlScriptFile;
+
+ CommandBuilder(HiveConf hiveConf, String userName, String password, String sqlScriptFile) {
+ this.hiveConf = hiveConf;
+ this.userName = userName;
+ this.password = password;
+ this.sqlScriptFile = sqlScriptFile;
+ }
+
+ String[] buildToRun() throws IOException {
+ return argsWith(password);
+ }
+
+ String buildToLog() throws IOException {
+ logScript();
+ return StringUtils.join(argsWith(BeeLine.PASSWD_MASK), " ");
+ }
+
+ private String[] argsWith(String password) throws IOException {
+ return new String[] { "-u",
+ HiveSchemaHelper.getValidConfVar(ConfVars.METASTORECONNECTURLKEY, hiveConf), "-d",
+ HiveSchemaHelper.getValidConfVar(ConfVars.METASTORE_CONNECTION_DRIVER, hiveConf), "-n",
+ userName, "-p", password, "-f", sqlScriptFile };
+ }
+
+ private void logScript() throws IOException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Going to invoke file that contains:");
+ try (BufferedReader reader = new BufferedReader(new FileReader(sqlScriptFile))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ LOG.debug("script: " + line);
+ }
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/hive/blob/ea87e0f2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0a55c7c..5d5e172 100644
--- a/pom.xml
+++ b/pom.xml
@@ -777,8 +777,15 @@
<version>${slf4j.version}</version>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>