Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 16 additions & 5 deletions core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -68,12 +69,13 @@ public class JdbcCatalog extends BaseMetastoreCatalog
private static final Logger LOG = LoggerFactory.getLogger(JdbcCatalog.class);
private static final Joiner SLASH = Joiner.on("/");

private FileIO io;
private FileIO io = null;
private String catalogName = "jdbc";
private String warehouseLocation;
private Object conf;
private JdbcClientPool connections;
private Map<String, String> catalogProperties;
private Function<Map<String, String>, FileIO> ioBuilder;

public JdbcCatalog() {}

Expand All @@ -95,10 +97,14 @@ public void initialize(String name, Map<String, String> properties) {
this.catalogName = name;
}

String fileIOImpl =
properties.getOrDefault(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.hadoop.HadoopFileIO");
this.io = CatalogUtil.loadFileIO(fileIOImpl, properties, conf);
if (null != ioBuilder) {
this.io = ioBuilder.apply(properties);
} else {
String ioImpl =
properties.getOrDefault(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.hadoop.HadoopFileIO");
this.io = CatalogUtil.loadFileIO(ioImpl, properties, conf);
}

try {
LOG.debug("Connecting to JDBC database {}", properties.get(CatalogProperties.URI));
Expand All @@ -116,6 +122,11 @@ public void initialize(String name, Map<String, String> properties) {
}
}

public void setFileIOBuilder(Function<Map<String, String>, FileIO> ioBuilder) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into adding this to BaseMetastoreCatalog but it didn't make sense. That class is not Configurable and creating an IO requires a Configuration when the subclasses implement it. As a result, this class would need to override both this method and a newFileIO method so it isn't worth it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as how we're duplicating this API across some catalogs, should we pull the set/create into an interface?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see whether we need this more broadly first. It's a pretty narrow use case at the moment.

Preconditions.checkState(null == io, "Cannot set IO builder after calling initialize");
this.ioBuilder = ioBuilder;
}

private void initializeCatalogTables() throws InterruptedException, SQLException {
LOG.trace("Creating database tables (if missing) to store iceberg catalog");
connections.run(
Expand Down
25 changes: 18 additions & 7 deletions core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class RESTSessionCatalog extends BaseSessionCatalog
OAuth2Properties.SAML1_TOKEN_TYPE);

private final Function<Map<String, String>, RESTClient> clientBuilder;
private Function<Map<String, String>, FileIO> ioBuilder;
Comment thread
rdblue marked this conversation as resolved.
Outdated
private Cache<String, AuthSession> sessions = null;
private AuthSession catalogAuth = null;
private boolean keepTokenRefreshed = true;
Expand Down Expand Up @@ -187,10 +188,7 @@ public void initialize(String name, Map<String, String> unresolved) {
client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
}

String ioImpl = mergedProps.get(CatalogProperties.FILE_IO_IMPL);
this.io =
CatalogUtil.loadFileIO(
ioImpl != null ? ioImpl : ResolvingFileIO.class.getName(), mergedProps, conf);
this.io = newFileIO(mergedProps);

this.snapshotMode =
SnapshotMode.valueOf(
Expand All @@ -205,6 +203,11 @@ public void initialize(String name, Map<String, String> unresolved) {
super.initialize(name, mergedProps);
}

public void setFileIOBuilder(Function<Map<String, String>, FileIO> ioBuilder) {
Preconditions.checkState(null == io, "Cannot set IO builder after calling initialize");
this.ioBuilder = ioBuilder;
}

private AuthSession session(SessionContext context) {
AuthSession session =
sessions.get(
Expand Down Expand Up @@ -762,16 +765,24 @@ private String fullTableName(TableIdentifier ident) {
return String.format("%s.%s", name(), ident);
}

private FileIO newFileIO(Map<String, String> properties) {
if (null != ioBuilder) {
return ioBuilder.apply(properties);
} else {
String ioImpl =
properties.getOrDefault(CatalogProperties.FILE_IO_IMPL, ResolvingFileIO.class.getName());
return CatalogUtil.loadFileIO(ioImpl, properties, conf);
}
}

private FileIO tableFileIO(Map<String, String> config) {
if (config.isEmpty()) {
return io; // reuse client and io since config is the same
}

Map<String, String> fullConf = RESTUtil.merge(properties(), config);
String ioImpl = fullConf.get(CatalogProperties.FILE_IO_IMPL);

return CatalogUtil.loadFileIO(
ioImpl != null ? ioImpl : ResolvingFileIO.class.getName(), fullConf, this.conf);
return newFileIO(fullConf);
}

private AuthSession tableSession(Map<String, String> tableConf, AuthSession parent) {
Expand Down