Haozhe Xie
Haozhe Xie

Reputation: 3666

ParseException about EOF in Hive

I can execute the SQL in the shell:

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

Here's the content in the 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

The struct of the table(named files) is

guid STRING
filename STRING
filepath STRING

If I execute the sql in Java, I got an exception:

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'

Here's the code:

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);

What should I do?

Upvotes: 3

Views: 28415

Answers (1)

Haozhe Xie
Haozhe Xie

Reputation: 3666

When you write a query in the shell, you should use ';' at the end of the SQL statement:

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

However, you CANNOT use ';' at the end of the SQL statement when you're using Java:

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

So, that's the reason cause the exception.

Upvotes: 10

Related Questions