@Test public void connectAndCreateDatabaseWithoutIssue() throws SQLException { HiveClient hiveClient = new HiveClient(driverName, "jdbc:hive2: hdfsTemp + "/garmadon_database"); hiveClient.execute("DESCRIBE DATABASE " + database); try { hiveClient.execute("DESCRIBE DATABASE not_created_database"); } catch (SQLException e) { assertTrue(e.getMessage().contains("Database does not exist: not_created_database")); } }
protected void execute(String query) throws SQLException { LOGGER.debug("Execute hql: {}", query); int maxAttempts = 5; for (int retry = 1; retry <= maxAttempts; ++retry) { try { stmt.execute(query); } catch (SQLException sqlException) { if (ExceptionUtils.indexOfThrowable(sqlException, TTransportException.class) != -1) { String exMsg = String.format("Retry connecting to hive (%d/%d)", retry, maxAttempts); if (retry <= maxAttempts) { LOGGER.warn(exMsg, sqlException); try { Thread.sleep(1000 * retry); connect(); } catch (Exception ignored) { } } else { LOGGER.error(exMsg, sqlException); throw sqlException; } } else { throw sqlException; } } } }
HiveClient { protected void execute(String query) throws SQLException { LOGGER.debug("Execute hql: {}", query); int maxAttempts = 5; for (int retry = 1; retry <= maxAttempts; ++retry) { try { stmt.execute(query); } catch (SQLException sqlException) { if (ExceptionUtils.indexOfThrowable(sqlException, TTransportException.class) != -1) { String exMsg = String.format("Retry connecting to hive (%d/%d)", retry, maxAttempts); if (retry <= maxAttempts) { LOGGER.warn(exMsg, sqlException); try { Thread.sleep(1000 * retry); connect(); } catch (Exception ignored) { } } else { LOGGER.error(exMsg, sqlException); throw sqlException; } } else { throw sqlException; } } } } }
HiveClient { protected void execute(String query) throws SQLException { LOGGER.debug("Execute hql: {}", query); int maxAttempts = 5; for (int retry = 1; retry <= maxAttempts; ++retry) { try { stmt.execute(query); } catch (SQLException sqlException) { if (ExceptionUtils.indexOfThrowable(sqlException, TTransportException.class) != -1) { String exMsg = String.format("Retry connecting to hive (%d/%d)", retry, maxAttempts); if (retry <= maxAttempts) { LOGGER.warn(exMsg, sqlException); try { Thread.sleep(1000 * retry); connect(); } catch (Exception ignored) { } } else { LOGGER.error(exMsg, sqlException); throw sqlException; } } else { throw sqlException; } } } } HiveClient(String driverName, String jdbcUrl, String database, String location); }
HiveClient { protected void execute(String query) throws SQLException { LOGGER.debug("Execute hql: {}", query); int maxAttempts = 5; for (int retry = 1; retry <= maxAttempts; ++retry) { try { stmt.execute(query); } catch (SQLException sqlException) { if (ExceptionUtils.indexOfThrowable(sqlException, TTransportException.class) != -1) { String exMsg = String.format("Retry connecting to hive (%d/%d)", retry, maxAttempts); if (retry <= maxAttempts) { LOGGER.warn(exMsg, sqlException); try { Thread.sleep(1000 * retry); connect(); } catch (Exception ignored) { } } else { LOGGER.error(exMsg, sqlException); throw sqlException; } } else { throw sqlException; } } } } HiveClient(String driverName, String jdbcUrl, String database, String location); void createDatabaseIfAbsent(String location); void createPartitionIfNotExist(String table, MessageType schema, String partition, String location); void close(); }
HiveClient { protected void execute(String query) throws SQLException { LOGGER.debug("Execute hql: {}", query); int maxAttempts = 5; for (int retry = 1; retry <= maxAttempts; ++retry) { try { stmt.execute(query); } catch (SQLException sqlException) { if (ExceptionUtils.indexOfThrowable(sqlException, TTransportException.class) != -1) { String exMsg = String.format("Retry connecting to hive (%d/%d)", retry, maxAttempts); if (retry <= maxAttempts) { LOGGER.warn(exMsg, sqlException); try { Thread.sleep(1000 * retry); connect(); } catch (Exception ignored) { } } else { LOGGER.error(exMsg, sqlException); throw sqlException; } } else { throw sqlException; } } } } HiveClient(String driverName, String jdbcUrl, String database, String location); void createDatabaseIfAbsent(String location); void createPartitionIfNotExist(String table, MessageType schema, String partition, String location); void close();  }