diff --git beeline/src/java/org/apache/hive/beeline/BeeLine.java beeline/src/java/org/apache/hive/beeline/BeeLine.java index 82077cc3a9..65ec560950 100644 --- beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -1324,7 +1324,16 @@ private int executeFile(String fileName) { } fileStream = fs.open(path); } else { - fileStream = new FileInputStream(fileName); + org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(fileName); + FileSystem fs; + HiveConf conf = new HiveConf(); + if (!path.toUri().isAbsolute()) { + fs = FileSystem.getLocal(conf); + path = fs.makeQualified(path); + } else { + fs = FileSystem.get(path.toUri(), conf); + } + fileStream = fs.open(path); } return execute(initializeConsoleReader(fileStream), !getOpts().getForce()); } catch (Throwable t) { diff --git beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java index 1fa6a75cb5..c9ff066a53 100644 --- beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java +++ beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java @@ -353,4 +353,19 @@ public void testMaxHistoryRows() throws Exception { Assert.assertTrue(bl.getOpts().getMaxHistoryRows() == 100); bl.close(); } + + /** + * Test the file parameter option + * @throws Exception + */ + @Test + public void testFileParam() throws Exception { + TestBeeline bl = new TestBeeline(); + String args[] = new String[] {"-u", "url", "-n", "name", + "-p", "password", "-d", "driver", "-f", "hdfs://myscript"}; + Assert.assertEquals(0, bl.initArgs(args)); + Assert.assertTrue(bl.connectArgs.equals("url name password driver")); + Assert.assertTrue(bl.getOpts().getScriptFile().equals("hdfs://myscript")); + } + }