Use of Impala service

Open Ports for Impala Service

Description Port
JDBC 32404
Impala Shell 32400

impala-shell Method

After the user logs on to the master node, the Impala-shell client is ready and the environment variable $IMPALA_HOME is set. The steps are as follows:

impala-shell
>           // enter interactive impala-shell
>connect ${impalad_server_ip}:32400; // connect impala server beeswax port
>select 1+1; // .Execute user's customized command.

JDBC Method

The user needs to first establish an SSH tunnel with the master node and then configure the Java system properties to implement JDBC over SSH tunnel.

  1. For the process of establishing an SSH tunnel with the master node, see establishing an SSH tunnel

  2. Configuring system properties

    • Specifying system properties through option -D in Java execution

      java -cp ${classpath} -DsocksProxyHost="127.0.0.1" -DsocksProxyPort="1080" JdbcTest
      
    • Specifying system properties through code

      package com.xiaomi.infra.galaxy.test.jdbc;
      
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;
      
      public class JDBCTest {
      
       private static final int jdbc_port = 32404;
       private static String jdbc_host = "172.31.0.249";
       private static String socks_port = "1080";
       private static String socks_host = "127.0.0.1";
       private static String SOCKS_VERSION = "5";
      
       public void testJdbc() {
         Statement statement = null;
         Connection conn = null;
         try {
           System.setProperty("socksProxyHost", socks_host);
           System.setProperty("socksProxyPort", socks_port);
           System.setProperty("socksProxyVersion", SOCKS_VERSION);
           Class.forName("org.apache.hive.jdbc.HiveDriver");
           String url = "jdbc:hive2://" + jdbc_host + ":" + jdbc_port + "/;auth=noSasl";
           conn = DriverManager.getConnection(url);
           statement = conn.createStatement();
           String sql = "select 1+1";
           ResultSet rs = statement.executeQuery(sql);
           while (rs.next()) {
             int count = rs.getInt(1);
             System.out.println(count);
           }
         } catch (Exception e) {
           e.printStackTrace();
         } finally {
           if (statement != null) {
             try {
               statement.close();
             } catch (SQLException e) {
               // ignore
             }
           }
           if (conn != null) {
             try {
               conn.close();
             } catch (SQLException e) {
               // ignore
             }
           }
      
         }
       }
      
       public static void main(String[] args) {
         JDBCTest test = new JDBCTest();
         test.testJdbc();
       }
      }
      

    NOTE: relies in hive-jdbc in pom

        <dependency>
          <groupId>org.apache.hive</groupId>
          <artifactId>hive-jdbc</artifactId>
          <version>0.13.1-cdh5.3.0</version>
        </dependency><dependency>