关于Hive中EOF的ParseException

时间:2013-06-12 11:18:24

标签: java hive

我可以在shell中执行SQL:

LOAD DATA LOCAL INPATH '/tmp/sql.txt' INTO TABLE files;

这是sql.txt中的内容:

4e6c924a-1fa2-4326-86eb-975d1007f0a6 FileScoreConverterTest.java /home/xiehaozhe/Development/Kloud-Document-Analyzer/kda/src/test/java/com/kda/filescore/type/FileScoreConverterTest.java
ab6ee610-c980-4ff7-b472-8546766e0f89 FileWordCountConverterTest.java /home/xiehaozhe/Development/Kloud-Document-Analyzer/kda/src/test/java/com/kda/filescore/type/FileWordCountConverterTest.java

表的结构(名为 files )是

guid STRING
filename STRING
filepath STRING

如果我在Java中执行sql,我会遇到异常:

Exception in thread "main" java.sql.SQLException: Query returned non-zero code: 40000, cause: FAILED: ParseException line 1:54 mismatched input ';' expecting EOF near 'files'

以下是代码:

Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
String sql = "LOAD DATA LOCAL INPATH '" + sqlFilePath + "' INTO TABLE files;";
Connection connection = DriverManager.getConnection(databaseAddress, databaseUsername, databasePassword);
Statement statement = connection.createStatement();
statement.executeQuery(sql);

我该怎么办?

1 个答案:

答案 0 :(得分:6)

在shell中编写查询时,应使用';'在SQL语句的末尾:

LOAD DATA LOCAL INPATH '/tmp/sql.txt' INTO TABLE files;

但是,你不能使用';'在使用Java时SQL语句的末尾:

LOAD DATA LOCAL INPATH '/tmp/sql.txt' INTO TABLE files

所以,这就是造成例外的原因。