use of java.sql.SQLTimeoutException in project ranger by apache.
the class PrestoClient method getSchemas.
private List<String> getSchemas(String needle, List<String> catalogs, List<String> schemas) throws HadoopException {
List<String> ret = new ArrayList<>();
if (con != null) {
Statement stat = null;
ResultSet rs = null;
String sql = null;
try {
if (catalogs != null && !catalogs.isEmpty()) {
for (String catalog : catalogs) {
sql = "SHOW SCHEMAS FROM \"" + StringEscapeUtils.escapeSql(catalog) + "\"";
try {
if (needle != null && !needle.isEmpty() && !needle.equals("*")) {
sql += " LIKE '" + StringEscapeUtils.escapeSql(needle) + "%'";
}
stat = con.createStatement();
rs = stat.executeQuery(sql);
while (rs.next()) {
String schema = rs.getString(1);
if (schemas != null && schemas.contains(schema)) {
continue;
}
ret.add(schema);
}
} finally {
close(rs);
close(stat);
rs = null;
stat = null;
}
}
}
} catch (SQLTimeoutException sqlt) {
String msgDesc = "Time Out, Unable to execute SQL [" + sql + "].";
HadoopException hdpException = new HadoopException(msgDesc, sqlt);
hdpException.generateResponseDataMap(false, getMessage(sqlt), msgDesc + ERR_MSG, null, null);
if (LOG.isDebugEnabled()) {
LOG.debug("<== PrestoClient.getSchemas() Error : ", sqlt);
}
throw hdpException;
} catch (SQLException sqle) {
String msgDesc = "Unable to execute SQL [" + sql + "].";
HadoopException hdpException = new HadoopException(msgDesc, sqle);
hdpException.generateResponseDataMap(false, getMessage(sqle), msgDesc + ERR_MSG, null, null);
if (LOG.isDebugEnabled()) {
LOG.debug("<== PrestoClient.getSchemas() Error : ", sqle);
}
throw hdpException;
}
}
return ret;
}
use of java.sql.SQLTimeoutException in project ranger by apache.
the class PrestoClient method getCatalogs.
private List<String> getCatalogs(String needle, List<String> catalogs) throws HadoopException {
List<String> ret = new ArrayList<>();
if (con != null) {
Statement stat = null;
ResultSet rs = null;
String sql = "SHOW CATALOGS";
try {
if (needle != null && !needle.isEmpty() && !needle.equals("*")) {
// Cannot use a prepared statement for this as presto does not support that
sql += " LIKE '" + StringEscapeUtils.escapeSql(needle) + "%'";
}
stat = con.createStatement();
rs = stat.executeQuery(sql);
while (rs.next()) {
String catalogName = rs.getString(1);
if (catalogs != null && catalogs.contains(catalogName)) {
continue;
}
ret.add(catalogName);
}
} catch (SQLTimeoutException sqlt) {
String msgDesc = "Time Out, Unable to execute SQL [" + sql + "].";
HadoopException hdpException = new HadoopException(msgDesc, sqlt);
hdpException.generateResponseDataMap(false, getMessage(sqlt), msgDesc + ERR_MSG, null, null);
} catch (SQLException se) {
String msg = "Unable to execute SQL [" + sql + "]. ";
HadoopException he = new HadoopException(msg, se);
he.generateResponseDataMap(false, getMessage(se), msg + ERR_MSG, null, null);
throw he;
} finally {
close(rs);
close(stat);
}
}
return ret;
}
use of java.sql.SQLTimeoutException in project ranger by apache.
the class PrestoClient method getTables.
private List<String> getTables(String needle, List<String> catalogs, List<String> schemas, List<String> tables) throws HadoopException {
List<String> ret = new ArrayList<>();
if (con != null) {
Statement stat = null;
ResultSet rs = null;
String sql = null;
if (catalogs != null && !catalogs.isEmpty() && schemas != null && !schemas.isEmpty()) {
try {
for (String catalog : catalogs) {
for (String schema : schemas) {
sql = "SHOW tables FROM \"" + StringEscapeUtils.escapeSql(catalog) + "\".\"" + StringEscapeUtils.escapeSql(schema) + "\"";
try {
if (needle != null && !needle.isEmpty() && !needle.equals("*")) {
sql += " LIKE '" + StringEscapeUtils.escapeSql(needle) + "%'";
}
stat = con.createStatement();
rs = stat.executeQuery(sql);
while (rs.next()) {
String table = rs.getString(1);
if (tables != null && tables.contains(table)) {
continue;
}
ret.add(table);
}
} finally {
close(rs);
close(stat);
rs = null;
stat = null;
}
}
}
} catch (SQLTimeoutException sqlt) {
String msgDesc = "Time Out, Unable to execute SQL [" + sql + "].";
HadoopException hdpException = new HadoopException(msgDesc, sqlt);
hdpException.generateResponseDataMap(false, getMessage(sqlt), msgDesc + ERR_MSG, null, null);
if (LOG.isDebugEnabled()) {
LOG.debug("<== PrestoClient.getTables() Error : ", sqlt);
}
throw hdpException;
} catch (SQLException sqle) {
String msgDesc = "Unable to execute SQL [" + sql + "].";
HadoopException hdpException = new HadoopException(msgDesc, sqle);
hdpException.generateResponseDataMap(false, getMessage(sqle), msgDesc + ERR_MSG, null, null);
if (LOG.isDebugEnabled()) {
LOG.debug("<== PrestoClient.getTables() Error : ", sqle);
}
throw hdpException;
}
}
}
return ret;
}
use of java.sql.SQLTimeoutException in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testSqlError.
@Test
public void testSqlError() throws SQLException {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
SQLException ex = new SQLException("sql-reason", "08S01", 9999);
ResourceException rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode());
ex = new SQLException("sql-reason", "40001", 9999);
rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode());
SQLTimeoutException tex = new SQLTimeoutException();
rEx = (ResourceException) jdbcConn.sqlError(tex, "sqlError");
assertEquals(ResourceException.SERVICE_UNAVAILABLE, rEx.getCode());
jdbcConn.close();
}
use of java.sql.SQLTimeoutException in project drill by apache.
the class DrillJdbc41Factory method newServerPreparedStatement.
private DrillJdbc41PreparedStatement newServerPreparedStatement(DrillConnectionImpl connection, StatementHandle h, Meta.Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
String sql = signature.sql;
try {
DrillRpcFuture<CreatePreparedStatementResp> respFuture = connection.getClient().createPreparedStatement(signature.sql);
CreatePreparedStatementResp resp;
try {
resp = respFuture.get();
} catch (InterruptedException e) {
// Preserve evidence that the interruption occurred so that code higher up
// on the call stack can learn of the interruption and respond to it if it
// wants to.
Thread.currentThread().interrupt();
throw new SQLException("Interrupted", e);
}
final RequestStatus status = resp.getStatus();
if (status != RequestStatus.OK) {
final String errMsgFromServer = resp.getError() != null ? resp.getError().getMessage() : "";
if (status == RequestStatus.TIMEOUT) {
logger.error("Request timed out to create prepare statement: {}", errMsgFromServer);
throw new SQLTimeoutException("Failed to create prepared statement: " + errMsgFromServer);
}
if (status == RequestStatus.FAILED) {
logger.error("Failed to create prepared statement: {}", errMsgFromServer);
throw new SQLException("Failed to create prepared statement: " + errMsgFromServer);
}
logger.error("Failed to create prepared statement. Unknown status: {}, Error: {}", status, errMsgFromServer);
throw new SQLException(String.format("Failed to create prepared statement. Unknown status: %s, Error: %s", status, errMsgFromServer));
}
return new DrillJdbc41PreparedStatement(connection, h, signature, resp.getPreparedStatement(), resultSetType, resultSetConcurrency, resultSetHoldability);
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw Helper.INSTANCE.createException("Error while preparing statement [" + sql + "]", e);
}
}
Aggregations