hive 0.14 获取执行情况日志

String myBC_DB_URL = "mybc:hive2://my-test-001:10000/default;"
                + "principal=" + loginUserPrinc + ";kerberosAuthType=kerberos;hive.server2.proxy.user=" + proxtUser;

        Connection con = DriverManager.getConnection(myBC_DB_URL);
        final HiveStatement stmt = (HiveStatement) con.createStatement();
        String tableName = "test_count";

        final String sql = "select count(*) from " + tableName;
        LOGGER.info("Running: " + sql);

        final CountDownLatch latch = new CountDownLatch(1);
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    long start = System.currentTimeMillis();
                    ResultSet res = stmt.executeQuery(sql);
                    while (res.next()) {
                        StringBuffer sb = new StringBuffer();
                        for (int i = 0; i < res.getMetaData().getColumnCount(); i++) {
                            sb.append(res.getString(i + 1)).append("\t");
                        }
                        LOGGER.info(sb);
                    }
                    if (res.next()) {
                        LOGGER.info(res.getString(1));
                    }
                    long end = System.currentTimeMillis();
                    LOGGER.info("query-" + Thread.currentThread().getId() + ":" + (end - start));
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    latch.countDown();
                }
            }
        });
        t.start();
        while (latch.getCount() != 0) {
            List<String> logs = stmt.getQueryLog();
            for (String log : logs) {
               /* if(log.contains("The url to track the job")||log.contains("Tracking URL =")||log.contains("Kill Command =")){
                    //not print
                }else{
                    LOGGER.info(log);
                }*/

                if(log.contains(" Stage-")){
                    LOGGER.info(log);
                }else{

                }

            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

相关推荐