Skip to content

Commit

Permalink
HIVE-19018: beeline -e now requires semicolon even when used with que…
Browse files Browse the repository at this point in the history
…ry from command line (Aihua Xu, reviewed by Yongzhi Chen)
  • Loading branch information
Aihua Xu committed Mar 30, 2018
1 parent eea7361 commit 52290e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions beeline/src/java/org/apache/hive/beeline/BeeLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ int initArgs(String[] args) {
int code = 0;
if (cl.getOptionValues('e') != null) {
commands = Arrays.asList(cl.getOptionValues('e'));
opts.setAllowMultiLineCommand(false); //When using -e, command is always a single line

}

if (!commands.isEmpty() && getOpts().getScriptFile() != null) {
Expand Down
1 change: 0 additions & 1 deletion beeline/src/java/org/apache/hive/beeline/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,6 @@ private boolean executeInternal(String sql, boolean call) {
* Check if the input line is a multi-line command which needs to read further
*/
public String handleMultiLineCmd(String line) throws IOException {
//When using -e, console reader is not initialized and command is always a single line
int[] startQuote = {-1};
line = HiveStringUtils.removeComments(line, startQuote);
while (isMultiLine(line) && beeLine.getOpts().isAllowMultiLineCommand()) {
Expand Down
16 changes: 16 additions & 0 deletions beeline/src/test/org/apache/hive/beeline/TestCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static org.apache.hive.common.util.HiveStringUtils.removeComments;
import static org.junit.Assert.assertEquals;

import java.io.IOException;

public class TestCommands {

@Test
Expand All @@ -43,5 +45,19 @@ public void testLinesEndingWithComments() {
assertEquals("'show --comments tables'", removeComments("'show --comments tables' --comments",escape));
assertEquals("'\"show --comments tables\"'", removeComments("'\"show --comments tables\"' --comments",escape));
}

/**
* Test the commands directly call from beeline.
* @throws IOException
*/
@Test
public void testBeelineCommands() throws IOException {
// avoid System.exit() call in beeline which causes JVM to exit and fails the test
System.setProperty(BeeLineOpts.PROPERTY_NAME_EXIT, "true");
// Verify the command without ';' at the end also works fine
BeeLine.mainWithInputRedirection(new String[] {"-u", "jdbc:hive2://", "-e", "select 3"}, null);
BeeLine.mainWithInputRedirection(
new String[] {"-u", "jdbc:hive2://", "-e", "create table t1(x int); show tables"}, null);
}
}

0 comments on commit 52290e7

Please sign in to comment.