Support Questions
Find answers, ask questions, and share your expertise

How can I get warning from impala from JDBC?

How can I get warning from impala from JDBC?

Hello, everyone!

I have encountered an issue with obtaining warning from query from my app.

Let's say I have a table in impala with DDL like this:

CREATE TABLE db1.t1 (
id int,
name string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ","
STORED AS TEXTFILE
LOCATION '/db1/t1';

Than I put CSV file below in table directory:

1,sdf
dasd,2


After  I  do "INVALIDATE METADATA" and "SELECT * FROM db1.t1", I got several warnings:

WARNINGS: Error converting column: 0 to INT
Error parsing row: file: hdfs://hdpmigr.gaz.ru:8020/db1/t1/t1.csv, before offset: 21

I want to get these warnings from my app using JDBC driver. 
Here is a simple class, where I want to print warnings above:

import java.sql.*;
public class Tst {
public static void main(String[] args) {
try(Connection conn = DriverManager.getConnection("jdbc:impala://127.0.0.1:21050");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from db1.t1")) {
System.out.println(conn.getWarnings());
System.out.println(stmt.getWarnings());
System.out.println(rs.getWarnings());
while(rs.next())
System.out.println(rs.getInt("id"));
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}

All three getWarnings print "null". The question is can I somehow get warnings which I receive from impala-shell? 

2 REPLIES 2

Re: How can I get warning from impala from JDBC?

Rising Star

I think you want to put the result set getWarnings() inside the while loop.

while(rs.next()){
System.out.println(rs.getInt("id"));
if (rs.getWarnings() != null ) {
System
.out.println(rs.getWarnings());
System.out.println(rs.clearWarnings());
}
}

According to the JDBC ResultSet docs,   ResultSet warnings are set for each row when you call a method on the ResultSet which you haven't done yet in your current code.    Also, warnings on multiple rows are appended which is why I added the clearWarning().

Re: How can I get warning from impala from JDBC?

Yeah, that was my bad. However, this didn't help. 
I want to get warnings that I get from impala-shell when warning like below happens. Or at least something that can indicate these warnings to process it properly. 

 

WARNINGS: Error converting column: 0 to DECIMAL(38,15)

Error parsing row: file: hdfs://hdpmigr.gaz.ru:8020/db1/t1/t1.csv, before offset: 52

 

Method getWarnings() doesn't help, probably there is another method to get it