diff --git beeline/src/java/org/apache/hive/beeline/Commands.java beeline/src/java/org/apache/hive/beeline/Commands.java index bcbc574..3b2d72e 100644 --- beeline/src/java/org/apache/hive/beeline/Commands.java +++ beeline/src/java/org/apache/hive/beeline/Commands.java @@ -889,9 +889,8 @@ private boolean sourceFileInternal(File sourceFile) throws IOException { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(sourceFile)); - String extra = reader.readLine(); - String lines = null; - while (extra != null) { + String lines = null, extra; + while ((extra = reader.readLine()) != null) { if (beeLine.isComment(extra)) { continue; } @@ -900,7 +899,6 @@ private boolean sourceFileInternal(File sourceFile) throws IOException { } else { lines += "\n" + extra; } - extra = reader.readLine(); } String[] cmds = lines.split(beeLine.getOpts().getDelimiter()); for (String c : cmds) { diff --git beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java index 8eaa683..28b0cf9 100644 --- beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java +++ beeline/src/test/org/apache/hive/beeline/cli/TestHiveCli.java @@ -47,6 +47,7 @@ private final static String SOURCE_CONTEXT3 = "create table if not exists test.testSrcTbl3(sc3 string);"; private final static String SOURCE_CONTEXT4 = "show tables;!ls;show tables;\nquit;"; + private final static String SOURCE_CONTEXT5 = "-- test;\n;show tables;\nquit;"; final static String CMD = "create database if not exists test;\ncreate table if not exists test.testTbl(a string, b " + "string);\n"; @@ -165,6 +166,14 @@ public void testSourceCmd3() { } @Test + public void testSourceCmd4() { + File f = generateTmpFile(SOURCE_CONTEXT5); + verifyCMD("source " + f.getPath() + ";", "testtbl", os, + new String[] { "--database", "test" }, ERRNO_OK, true); + f.delete(); + } + + @Test public void testSqlFromCmd() { verifyCMD(null, "", os, new String[] { "-e", "show databases;" }, ERRNO_OK, true); }