Skip to content

Commit

Permalink
Revert "HIVE-15550: fix arglist logging in schematool (Anishek Agarwa…
Browse files Browse the repository at this point in the history
…l via Thejas Nair)"

This reverts commit ea87e0f.
  • Loading branch information
jcamachor committed Jan 18, 2017
1 parent a6148a5 commit 3792a4a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 65 deletions.
12 changes: 2 additions & 10 deletions beeline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

<properties>
<hive.path.to.root>..</hive.path.to.root>
<powermock.version>1.6.6</powermock.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -120,15 +119,8 @@
<scope>test</scope>
</dependency>
<dependency>
<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>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
80 changes: 34 additions & 46 deletions beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,38 @@ private void runBeeLine(String scriptDir, String scriptFile)

// Generate the beeline args per hive conf and execute the given script
public void runBeeLine(String sqlScriptFile) throws IOException {
CommandBuilder builder = new CommandBuilder(hiveConf, userName, passWord, sqlScriptFile);
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();
}
}
}

// run the script using Beeline
try (BeeLine beeLine = new BeeLine()) {
BeeLine beeLine = new BeeLine();
try {
if (!verbose) {
beeLine.setOutputStream(new PrintStream(new NullOutputStream()));
beeLine.getOpts().setSilent(true);
Expand All @@ -828,53 +856,13 @@ public void runBeeLine(String sqlScriptFile) throws IOException {
// 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 <" + builder.buildToLog() + ">");
int status = beeLine.begin(builder.buildToRun(), null);
LOG.debug("Going to run command <" + StringUtils.join(argList, " ") + ">");
int status = beeLine.begin(argList.toArray(new String[0]), null);
if (status != 0) {
throw new IOException("Schema script failed, errorcode " + status);
}
}
}

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);
}
}
}
} finally {
beeLine.close();
}
}

Expand Down
11 changes: 2 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,8 @@
<version>${slf4j.version}</version>
</dependency>
<dependency>
<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>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit 3792a4a

Please sign in to comment.