Skip to content

Commit

Permalink
HIVE-1415: add CLI command for executing a SQL script
Browse files Browse the repository at this point in the history
(Edward Capriolo via jvs)



git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1043849 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
John Sichi committed Dec 9, 2010
1 parent 6cef02e commit 0aecd37
Show file tree
Hide file tree
Showing 6 changed files with 553 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ Trunk - Unreleased
HIVE-1834 more debugging for locking
(namit via He Yongqiang)

HIVE-1415: add CLI command for executing a SQL script
(Edward Capriolo via jvs)

OPTIMIZATIONS

BUG FIXES
Expand Down
14 changes: 14 additions & 0 deletions cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ public int processCmd(String cmd) {
// this counts as a successful run
System.exit(0);

} else if (tokens[0].equalsIgnoreCase("source")) {
File sourceFile = new File(cmd_1);
if (! sourceFile.isFile()){
console.printError("File: "+ cmd_1 + " is not a file.");
ret = 1;
} else {
try {
this.processFile(cmd_1);
} catch (IOException e) {
console.printError("Failed processing file "+ cmd_1 +" "+ e.getLocalizedMessage(),
org.apache.hadoop.util.StringUtils.stringifyException(e));
ret = 1;
}
}
} else if (cmd_trimmed.startsWith("!")) {

String shell_cmd = cmd_trimmed.substring(1);
Expand Down
4 changes: 4 additions & 0 deletions data/files/source.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EXPLAIN
SELECT x.* FROM SRC x;

SELECT x.* FROM SRC x;
5 changes: 5 additions & 0 deletions docs/xdocs/language_manual/cli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ Use ";" (semicolon) to terminate commands. Comments in scripts can be specified
<td>Executes a hive query and prints results to standard out</td>
</tr>

<tr>
<td>source FILE</td>
<td>Used to execute a script file inside the CLI.</td>
</tr>

</table>

Sample Usage:
Expand Down
1 change: 1 addition & 0 deletions ql/src/test/queries/clientpositive/source.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source ../data/files/source.txt;
Loading

0 comments on commit 0aecd37

Please sign in to comment.