Updated on 2026-04-10 GMT+08:00

Impala Development Rules

Loading the Hive JDBC Driver

When a client application connects to the impalad daemon via JDBC, you must first load the Hive JDBC driver class org.apache.hive.jdbc.HiveDriver.

Therefore, you must use the current class loader to load the driver class before initializing the client application.

If the required JAR files are missing from the classpath, the client application will throw "Class Not Found" and terminate.

Example:

Class.forName("org.apache.hive.jdbc.HiveDriver").newInstance();

Obtain the database connection.

Use the driver management class java.sql.DriverManager of the JDK to obtain an Impalad database connection.

The URL of the Impalad database is as follows: url="jdbc:hive2://xxx.xxx.xxx.xxx:21050;auth=KERBEROS;principal=impala/hadoop.hadoop.com@HADOOP.COM;user.principal=impala/hadoop.hadoop.com;user.keytab=conf/impala.keytab";

The username and password are null or empty because authentication has been performed successfully.

// Establish a connection.

connection = DriverManager.getConnection(url, "", "");

// Execute an Impala SQL statement.

Execute an Impala SQL statement. Note that Impala SQL statement cannot end with a semicolon (;).

Correct example:

String sql = "SELECT COUNT(*) FROM employees_info";
Connection connection = DriverManager.getConnection(url, "", "");
PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();

Incorrect example:

String sql = "SELECT COUNT(*) FROM employees_info;";
Connection connection = DriverManager.getConnection(url, "", "");
PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();

Using Impala SQL Syntax to Check Whether a Field is Null

Use is null to determine if a field is empty (contains no value). Use is not null to verify if a field contains a value.

If you use is null to check a String field with a length of 0 (an empty string), the operation returns False. In this case, you must use col = '' to identify empty strings and col != '' to identify non-empty strings.

Correct example:

select * from default.tbl_src where id is null;
select * from default.tbl_src where id is not null;
select * from default.tbl_src where name = '';
select * from default.tbl_src where name != '';

Incorrect example:

select * from default.tbl_src where id = null;
select * from default.tbl_src where id != null;
select * from default.tbl_src where name is null;
select * from default.tbl_src where name is not null; Note: The id field in the tbl_src table uses the Int data type, while the name field uses the String data type.

Multithreaded Secure Login Mode

If multiple threads are used for login, all threads must use the relogin mode for subsequent login attempts after the application has successfully performed its initial login.

Login sample code:

  private Boolean login(Configuration conf){
    boolean flag = false;
    UserGroupInformation.setConfiguration(conf);
    
    try {
      UserGroupInformation.loginUserFromKeytab(conf.get(PRINCIPAL), conf.get(KEYTAB));
      System.out.println("UserGroupInformation.isLoginKeytabBased(): " +UserGroupInformation.isLoginKeytabBased());
      flag = true;
    } catch (IOException e) {
      e.printStackTrace();
    }
    return flag;
    
  }

Relogin sample code:

public Boolean relogin(){
        boolean flag = false;
        try {
            
          UserGroupInformation.getLoginUser().reloginFromKeytab();
          System.out.println("UserGroupInformation.isLoginKeytabBased(): " +UserGroupInformation.isLoginKeytabBased());
          flag = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return flag;
    }

Avoiding Concurrent Read and Write Operations on the Same Table

Currently, Hive does not support concurrent operations on the same table. You must avoid performing read and write tasks simultaneously on the same table. Otherwise, query results may be inaccurate or the task may fail.