private static boolean isPrestoQueryInvalid(SQLException e) { for (Throwable t = e.getCause(); t != null; t = t.getCause()) { if (t.toString().contains(".SemanticException:")) { return true; } if (t.toString().contains(".ParsingException:")) { return true; } if (nullToEmpty(t.getMessage()).matches("Function .* not registered")) { return true; } } return false; }
public DBConnectionException(String uri, SQLException e) { super("Connection URI:" + uri + "; " + e.getMessage(), e.getSQLState(), e.getErrorCode(), e.getCause()); } }
Throwable cause = e.getCause(); for (int i = 0; i < 5 && cause != null; ++i) { if (cause instanceof SocketTimeoutException) {
public void handleCompletion() throws SQLException { updateGeneratedKeys(); SQLException batchException = getException(); if (batchException != null) { if (isAutoCommit()) { // Re-create batch exception since rows after exception might indeed succeed. BatchUpdateException newException = new BatchUpdateException( batchException.getMessage(), batchException.getSQLState(), uncompressUpdateCount() ); newException.initCause(batchException.getCause()); SQLException next = batchException.getNextException(); if (next != null) { newException.setNextException(next); } batchException = newException; } throw batchException; } }
@Test(expected = SQLException.class) public void testConvertFromError() throws Exception { final Statement statement = connection.createStatement(); try { statement.executeUpdate("select CONVERT_FROM('1','INTEGER') from (values(1))"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertTrue("No expected current \"UNSUPPORTED_OPERATION ERROR\" and/or \"Did you mean\"", e.getMessage().matches("^UNSUPPORTED_OPERATION ERROR(.|\\n)*Did you mean(.|\\n)*")); throw e; } } }
@Test(expected = SQLException.class) public void testMaterializingError() throws Exception { final Statement statement = connection.createStatement(); try { statement.executeUpdate("select (res1 = 2016/09/22) res2 from (select (case when (false) then null else " + "cast('2016/09/22' as date) end) res1 from (values(1)) foo) foobar"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertThat("No expected current \"PLAN ERROR\"", e.getMessage(), startsWith("PLAN ERROR")); throw e; } }
@Test(expected = SQLException.class) public void testExecuteThrowsRight1() throws Exception { final Statement statement = connection.createStatement(); try { statement.execute("SELECT one case of syntax error"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"", e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR"))); throw e; } }
@Test(expected = SQLException.class) public void testExecuteUpdateThrowsRight2() throws Exception { final Statement statement = connection.createStatement(); try { statement.executeUpdate("naughty, naughty query 3"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"", e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR"))); throw e; } }
@Test(expected = SQLException.class) public void testExecuteQueryThrowsRight2() throws Exception { final Statement statement = connection.createStatement(); try { statement.executeQuery("BAD QUERY 1"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"", e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR"))); throw e; } }
@Test(expected = SQLException.class) public void testExecuteQueryThrowsRight1() throws Exception { final Statement statement = connection.createStatement(); try { statement.executeQuery("SELECT one case of syntax error"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"", e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR"))); throw e; } }
@Test(expected = SQLException.class) public void testExecuteUpdateThrowsRight1() throws Exception { final Statement statement = connection.createStatement(); try { statement.executeUpdate("SELECT one case of syntax error"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"", e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR"))); throw e; } }
@Test(expected = SQLException.class) public void testExecuteThrowsRight2() throws Exception { final Statement statement = connection.createStatement(); try { statement.execute("worse query 2"); } catch (SQLException e) { assertThat("Null getCause(); missing expected wrapped exception", e.getCause(), notNullValue()); assertThat("Unexpectedly wrapped another SQLException", e.getCause(), not(instanceOf(SQLException.class))); assertThat("getCause() not UserRemoteException as expected", e.getCause(), instanceOf(UserRemoteException.class)); assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"", e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR"))); throw e; } }
@Test public void testDirectConnectionConnectTriesGreaterThanDrillbitCount() throws SQLException { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=5", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); assertTrue(ex.getCause() instanceof RpcException); assertTrue(ex.getCause().getCause() instanceof ExecutionException); } }
@Test public void testDirectConnectionConnectTriesLessThanDrillbitCount() throws SQLException { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=1", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); assertTrue(ex.getCause() instanceof RpcException); assertTrue(ex.getCause().getCause() instanceof ExecutionException); } }
@Test public void testDirectConnectionNegativeConnectTries() throws SQLException { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=-5", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); assertTrue(ex.getCause() instanceof RpcException); assertTrue(ex.getCause().getCause() instanceof ExecutionException); } }
@Test public void testDirectConnectionConnectTriesEqualsDrillbitCount() throws SQLException { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;" + "tries=2", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); assertTrue(ex.getCause() instanceof RpcException); assertTrue(ex.getCause().getCause() instanceof ExecutionException); } }
@Test public void testDirectConnectionZeroConnectTries() throws SQLException { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=0", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); assertTrue(ex.getCause() instanceof RpcException); assertTrue(ex.getCause().getCause() instanceof ExecutionException); } }
@Test public void testDirectConnectionInvalidConnectTries() throws SQLException { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=abc", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); assertTrue(ex.getCause() instanceof InvalidConnectionInfoException); } }
@Test public void testZKConnectionInvalidConnectTries() throws SQLException { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=abc", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); assertTrue(ex.getCause() instanceof InvalidConnectionInfoException); } } }