Skip to content

Commit 10fcb22

Browse files
authored
Fixed issue where the getTable API was incorrectly returning TableNotFoundException instead of ConnectorException. (Netflix#246)
* Fixed issue where the getTable API was incorrectly returning TableNotFoundException instead of ConnectorException.
1 parent 029323e commit 10fcb22

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

metacat-connector-jdbc/src/main/java/com/netflix/metacat/connector/jdbc/services/JdbcConnectorTableService.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.netflix.metacat.common.dto.Sort;
2626
import com.netflix.metacat.common.server.connectors.ConnectorRequestContext;
2727
import com.netflix.metacat.common.server.connectors.ConnectorTableService;
28+
import com.netflix.metacat.common.server.connectors.exception.ConnectorException;
2829
import com.netflix.metacat.common.server.connectors.exception.TableNotFoundException;
2930
import com.netflix.metacat.common.server.connectors.model.FieldInfo;
3031
import com.netflix.metacat.common.server.connectors.model.TableInfo;
@@ -147,7 +148,7 @@ public TableInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull fi
147148
log.debug("Finished getting table metadata for qualified name {} for request {}", name, context);
148149
return result;
149150
} catch (final SQLException se) {
150-
throw this.exceptionMapper.toConnectorException(se, name);
151+
throw new ConnectorException(se.getMessage(), se);
151152
}
152153
}
153154

@@ -156,7 +157,7 @@ public TableInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull fi
156157
* @param connection db connection
157158
* @param tableInfo table info
158159
*/
159-
protected void setTableInfoDetails(final Connection connection, final TableInfo tableInfo) throws SQLException { }
160+
protected void setTableInfoDetails(final Connection connection, final TableInfo tableInfo) { }
160161

161162
/**
162163
* {@inheritDoc}

metacat-connector-mysql/src/main/java/com/netflix/metacat/connector/mysql/MySqlConnectorTableService.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
import com.netflix.metacat.connector.jdbc.JdbcExceptionMapper;
88
import com.netflix.metacat.connector.jdbc.JdbcTypeConverter;
99
import com.netflix.metacat.connector.jdbc.services.JdbcConnectorTableService;
10+
import lombok.extern.slf4j.Slf4j;
1011

1112
import javax.sql.DataSource;
1213
import java.sql.Connection;
1314
import java.sql.PreparedStatement;
1415
import java.sql.ResultSet;
15-
import java.sql.SQLException;
1616

1717
/**
1818
* Mysql table service implementation.
1919
*
2020
* @author amajumdar
2121
* @since 1.2.0
2222
*/
23+
@Slf4j
2324
public class MySqlConnectorTableService extends JdbcConnectorTableService {
2425
private static final String COL_CREATE_TIME = "create_time";
2526
private static final String COL_UPDATE_TIME = "update_time";
@@ -44,7 +45,7 @@ public MySqlConnectorTableService(
4445
* {@inheritDoc}
4546
*/
4647
@Override
47-
protected void setTableInfoDetails(final Connection connection, final TableInfo tableInfo) throws SQLException {
48+
protected void setTableInfoDetails(final Connection connection, final TableInfo tableInfo) {
4849
final QualifiedName tableName = tableInfo.getName();
4950
try (
5051
final PreparedStatement statement = connection.prepareStatement(SQL_GET_AUDIT_INFO)
@@ -59,6 +60,8 @@ protected void setTableInfoDetails(final Connection connection, final TableInfo
5960
tableInfo.setAudit(auditInfo);
6061
}
6162
}
63+
} catch (final Exception ignored) {
64+
log.info("Ignoring. Error getting the audit info for table {}", tableName);
6265
}
6366
}
6467
}

metacat-connector-snowflake/src/main/java/com/netflix/metacat/connector/snowflake/SnowflakeConnectorTableService.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
import com.netflix.metacat.connector.jdbc.JdbcExceptionMapper;
2828
import com.netflix.metacat.connector.jdbc.JdbcTypeConverter;
2929
import com.netflix.metacat.connector.jdbc.services.JdbcConnectorTableService;
30+
import lombok.extern.slf4j.Slf4j;
3031

3132
import javax.annotation.Nonnull;
3233
import javax.annotation.Nullable;
3334
import javax.sql.DataSource;
3435
import java.sql.Connection;
3536
import java.sql.PreparedStatement;
3637
import java.sql.ResultSet;
37-
import java.sql.SQLException;
3838
import java.util.List;
3939

4040
/**
@@ -43,6 +43,7 @@
4343
* @author amajumdar
4444
* @since 1.2.0
4545
*/
46+
@Slf4j
4647
public class SnowflakeConnectorTableService extends JdbcConnectorTableService {
4748
private static final String COL_CREATED = "CREATED";
4849
private static final String COL_LAST_ALTERED = "LAST_ALTERED";
@@ -137,7 +138,7 @@ public boolean exists(@Nonnull final ConnectorRequestContext context, @Nonnull f
137138
* {@inheritDoc}
138139
*/
139140
@Override
140-
protected void setTableInfoDetails(final Connection connection, final TableInfo tableInfo) throws SQLException {
141+
protected void setTableInfoDetails(final Connection connection, final TableInfo tableInfo) {
141142
final QualifiedName tableName = getSnowflakeName(tableInfo.getName());
142143
try (
143144
final PreparedStatement statement = connection.prepareStatement(SQL_GET_AUDIT_INFO)
@@ -153,6 +154,8 @@ protected void setTableInfoDetails(final Connection connection, final TableInfo
153154
tableInfo.setAudit(auditInfo);
154155
}
155156
}
157+
} catch (final Exception ignored) {
158+
log.info("Ignoring. Error getting the audit info for table {}", tableName);
156159
}
157160
}
158161
}

metacat-connector-snowflake/src/test/groovy/com/netflix/metacat/connector/snowflake/SnowflakeConnectorTableServiceSpec.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class SnowflakeConnectorTableServiceSpec extends Specification {
155155
then:
156156
1 * connection.prepareStatement(_) >> statement
157157
1 * statement.executeQuery() >> {throw new SQLException()}
158-
thrown(SQLException)
158+
noExceptionThrown()
159159
when:
160160
table = TableInfo.builder().name(name).build()
161161
this.service.setTableInfoDetails(connection, table)

0 commit comments

Comments
 (0)