Skip to content

Commit

Permalink
Merge pull request #11 from yas-okadatech/27783-catalog
Browse files Browse the repository at this point in the history
fix: listing table and columns were executed with null category because it specify database name instead of category name.
  • Loading branch information
yas-okadatech authored Oct 24, 2024
2 parents 213fa8a + ff237d8 commit 881c4f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/embulk/output/DatabricksOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ public Optional<JdbcSchema> newJdbcSchemaFromTableIfExists(
return Optional.empty();
}

DatabricksOutputConnection conn = (DatabricksOutputConnection) connection;
DatabaseMetaData dbm = connection.getMetaData();
String escape = dbm.getSearchStringEscape();

ResultSet rs =
dbm.getPrimaryKeys(table.getDatabase(), table.getSchemaName(), table.getTableName());
dbm.getPrimaryKeys(conn.getCatalogName(), table.getSchemaName(), table.getTableName());
final HashSet<String> primaryKeysBuilder = new HashSet<>();
try {
while (rs.next()) {
Expand All @@ -207,7 +208,7 @@ public Optional<JdbcSchema> newJdbcSchemaFromTableIfExists(
// https://docs.databricks.com/en/sql/language-manual/data-types/timestamp-ntz-type.html#notes
rs =
dbm.getColumns(
JdbcUtils.escapeSearchString(table.getDatabase(), escape),
JdbcUtils.escapeSearchString(conn.getCatalogName(), escape),
JdbcUtils.escapeSearchString(table.getSchemaName(), escape),
JdbcUtils.escapeSearchString(table.getTableName(), escape),
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean tableExists(TableIdentifier table) throws SQLException {
try (ResultSet rs =
connection
.getMetaData()
.getTables(table.getDatabase(), table.getSchemaName(), table.getTableName(), null)) {
.getTables(catalogName, table.getSchemaName(), table.getTableName(), null)) {
while (rs.next()) {
if (isAvailableTableMetadataInConnection(rs, table)) {
return true;
Expand All @@ -62,6 +62,10 @@ public boolean isAvailableTableMetadataInConnection(ResultSet rs, TableIdentifie
// null
// and one Databricks connection has multiple available catalogs (databases).

// NOTE: maybe this logic is not necessary anymore after this PR:
// https://github.com/trocco-io/embulk-output-databricks/pull/11
// But I'm not sure, so I'll keep it for now.

if (tableIdentifier.getDatabase() == null) {
logger.trace("tableIdentifier.getDatabase() == null, check by instance variable");
if (!rs.getString("TABLE_CAT").equalsIgnoreCase(catalogName)) {
Expand Down Expand Up @@ -295,4 +299,8 @@ private String buildColumns(JdbcSchema schema, String prefix) {
}
return sb.toString();
}

public String getCatalogName() {
return catalogName;
}
}

0 comments on commit 881c4f1

Please sign in to comment.