private static String getExtendedExplain(Statement stmt, String query) throws SQLException {
    StringBuilder sb = new StringBuilder(2048);
    try (ResultSet rs = stmt.executeQuery("explain extended " + query)) {
      while (rs.next()) {
        sb.append(rs.getString(1)).append('\n');
      }
    }
    return sb.toString();
  }
Get Extended Explain output via jdbc.
itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2ErasureCoding.java