Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table exists check in the jdbc storage plugin #11392

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Update BanyanDB Java Client to 0.5.0.
* Fix getInstances query in the BanyanDB Metadata DAO.
* BanyanDBStorageClient: Add `keepAliveProperty` API.
* Fix table exists check in the JDBC Storage Plugin.

#### UI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void registerChecker(HealthChecker healthChecker) {
public boolean indexExists(final String table,
final String index) throws SQLException {
try (final var connection = getConnection();
final var resultSet = connection.getMetaData().getIndexInfo(null, null, table, false, false)) {
final var resultSet = connection.getMetaData().getIndexInfo(connection.getCatalog(), null, table, false, false)) {
while (resultSet.next()) {
if (resultSet.getString("INDEX_NAME").equalsIgnoreCase(index)) {
return true;
Expand All @@ -164,14 +164,14 @@ public boolean indexExists(final String table,

public boolean tableExists(final String table) throws SQLException {
try (final var conn = getConnection();
final var result = conn.getMetaData().getTables(null, null, table, null)) {
final var result = conn.getMetaData().getTables(conn.getCatalog(), null, table, null)) {
return result.next();
}
}

public Set<String> getTableColumns(final String table) throws SQLException {
try (final var conn = getConnection();
final var result = conn.getMetaData().getColumns(null, null, table, null)) {
final var result = conn.getMetaData().getColumns(conn.getCatalog(), null, table, null)) {
final var columns = new HashSet<String>();
while (result.next()) {
columns.add(result.getString("COLUMN_NAME").toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void deleteHistory(Model model, String timeBucketColumnName, int ttl) {
final var tableName = TableHelper.getTableName(model);

try (final var conn = jdbcClient.getConnection();
final var result = conn.getMetaData().getTables(null, null, tableName + "%", new String[]{"TABLE"})) {
final var result = conn.getMetaData().getTables(conn.getCatalog(), null, tableName + "%", new String[]{"TABLE"})) {
while (result.next()) {
tablesToDrop.add(result.getString("TABLE_NAME"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void test() throws SQLException {
var jdbcHistoryDeleteDAO = new JDBCHistoryDeleteDAO(jdbcClient, tableHelper, tableInstaller, clock);
jdbcHistoryDeleteDAO.deleteHistory(model, "time_bucket", 3);
try (final var conn = jdbcClient.getConnection();
final var rs = conn.getMetaData().getTables(null, null, "service_traffic_20230317", null)) {
final var rs = conn.getMetaData().getTables(conn.getCatalog(), null, "service_traffic_20230317", null)) {
assertThat(rs.next()).isTrue();
}

Expand All @@ -131,12 +131,12 @@ void test() throws SQLException {
jdbcHistoryDeleteDAO = new JDBCHistoryDeleteDAO(jdbcClient, tableHelper, tableInstaller, clock);
jdbcHistoryDeleteDAO.deleteHistory(model, "time_bucket", 3);
try (final var conn = jdbcClient.getConnection();
final var rs = conn.getMetaData().getTables(null, null, "service_traffic_20230317", null)) {
final var rs = conn.getMetaData().getTables(conn.getCatalog(), null, "service_traffic_20230317", null)) {
assertThat(rs.next()).isFalse();
}
// ... and should create the new table
try (final var conn = jdbcClient.getConnection();
final var rs = conn.getMetaData().getTables(null, null, "service_traffic_20230322", null)) {
final var rs = conn.getMetaData().getTables(conn.getCatalog(), null, "service_traffic_20230322", null)) {
assertThat(rs.next()).isTrue();
}
}
Expand Down
Loading