Skip to content

Commit

Permalink
HIVE-12612: beeline always exits with 0 status when reading query fro…
Browse files Browse the repository at this point in the history
…m standard input (Reuben Kuhnert, reviewed by Sergio Pena)
  • Loading branch information
Sergio Pena committed Apr 1, 2016
1 parent 03b81bc commit ac273b6
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 13 deletions.
169 changes: 169 additions & 0 deletions beeline/pom.xml.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.hive</groupId>
<artifactId>hive</artifactId>
<version>2.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>hive-beeline</artifactId>
<packaging>jar</packaging>
<name>Hive Beeline</name>

<properties>
<hive.path.to.root>..</hive.path.to.root>
</properties>

<dependencies>
<!-- dependencies are always listed in sorted order by groupId, artifectId -->
<!-- intra-project -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-metastore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-shims</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>${project.version}</version>
</dependency>
<!-- inter-project -->
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>${libthrift.version}</version>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>${super-csv.version}</version>
</dependency>
<!-- test intra-project -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- test inter-project -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>${hadoop.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>sources</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<sourceDirectory>${basedir}/src/java</sourceDirectory>
<testSourceDirectory>${basedir}/src/test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
18 changes: 12 additions & 6 deletions beeline/src/java/org/apache/hive/beeline/BeeLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -953,26 +953,32 @@ private int executeFile(String fileName) {
}

private int execute(ConsoleReader reader, boolean exitOnError) {
String line;
int lastExecutionResult = ERRNO_OK;
while (!exit) {
try {
// Execute one instruction; terminate on executing a script if there is an error
// in silent mode, prevent the query and prompt being echoed back to terminal
line = (getOpts().isSilent() && getOpts().getScriptFile() != null) ? reader
String line = (getOpts().isSilent() && getOpts().getScriptFile() != null) ? reader
.readLine(null, ConsoleReader.NULL_MASK) : reader.readLine(getPrompt());

// trim line
line = (line == null) ? null : line.trim();
if (line != null) {
line = line.trim();
}

if (!dispatch(line) && exitOnError) {
return ERRNO_OTHER;
if (!dispatch(line)) {
lastExecutionResult = ERRNO_OTHER;
if (exitOnError) break;
} else if (line != null) {
lastExecutionResult = ERRNO_OK;
}

} catch (Throwable t) {
handleException(t);
return ERRNO_OTHER;
}
}
return ERRNO_OK;
return lastExecutionResult;
}

@Override
Expand Down
15 changes: 8 additions & 7 deletions beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class TestHiveCli {
private static final Logger LOG = LoggerFactory.getLogger(TestHiveCli.class.getName());
private static final int ERRNO_OK = 0;
private static final int ERRNO_ARGS = 1;
private static final int ERRNO_OTHER = 2;

private final static String SOURCE_CONTEXT =
"create table if not exists test.testSrcTbl(sc1 string);";
Expand Down Expand Up @@ -101,7 +102,7 @@ private void verifyCMD(String CMD, String keywords, OutputStream os, String[] op

@Test
public void testInValidCmd() {
verifyCMD("!lss\n", "Failed to execute lss", errS, null, ERRNO_OK, true);
verifyCMD("!lss\n", "Failed to execute lss", errS, null, ERRNO_OTHER, true);
}

@Test
Expand Down Expand Up @@ -159,7 +160,7 @@ public void testSourceCmd2() {
public void testSourceCmd3() {
File f = generateTmpFile(SOURCE_CONTEXT4);
verifyCMD("source " + f.getPath() + ";" + "desc testSrcTbl4;\nquit;\n", "src", os,
new String[] { "--database", "test" }, ERRNO_OK, true);
new String[] { "--database", "test" }, ERRNO_OTHER, true);
f.delete();
}

Expand Down Expand Up @@ -205,34 +206,34 @@ public void testVariablesForSource() {
@Test
public void testErrOutput() {
verifyCMD("show tables;set system:xxx=5;set system:yyy=${system:xxx};\nlss;",
"cannot recognize input near 'lss' '<EOF>' '<EOF>'", errS, null, ERRNO_OK, true);
"cannot recognize input near 'lss' '<EOF>' '<EOF>'", errS, null, ERRNO_OTHER, true);
}

@Test
public void testUseCurrentDB1() {
verifyCMD(
"create database if not exists testDB; set hive.cli.print.current.db=true;use testDB;\n"
+ "use default;drop if exists testDB;", "hive (testDB)>", os, null, ERRNO_OK, true);
+ "use default;drop if exists testDB;", "hive (testDB)>", os, null, ERRNO_OTHER, true);
}

@Test
public void testUseCurrentDB2() {
verifyCMD(
"create database if not exists testDB; set hive.cli.print.current.db=true;use\ntestDB;\nuse default;drop if exists testDB;",
"hive (testDB)>", os, null, ERRNO_OK, true);
"hive (testDB)>", os, null, ERRNO_OTHER, true);
}

@Test
public void testUseCurrentDB3() {
verifyCMD(
"create database if not exists testDB; set hive.cli.print.current.db=true;use testDB;\n"
+ "use default;drop if exists testDB;", "hive (testDB)>", os, null, ERRNO_OK, true);
+ "use default;drop if exists testDB;", "hive (testDB)>", os, null, ERRNO_OTHER, true);
}

@Test
public void testUseInvalidDB() {
verifyCMD("set hive.cli.print.current.db=true;use invalidDB;",
"hive (invalidDB)>", os, null, ERRNO_OK, false);
"hive (invalidDB)>", os, null, ERRNO_OTHER, false);
}

@Test
Expand Down

0 comments on commit ac273b6

Please sign in to comment.