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

Allow JDBC connector to define procedure #73

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.prestosql.plugin.jdbc;

import com.google.common.collect.ImmutableSet;
import io.airlift.bootstrap.LifeCycleManager;
import io.airlift.log.Logger;
import io.prestosql.spi.connector.Connector;
Expand All @@ -22,11 +23,13 @@
import io.prestosql.spi.connector.ConnectorRecordSetProvider;
import io.prestosql.spi.connector.ConnectorSplitManager;
import io.prestosql.spi.connector.ConnectorTransactionHandle;
import io.prestosql.spi.procedure.Procedure;
import io.prestosql.spi.transaction.IsolationLevel;

import javax.inject.Inject;

import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand All @@ -46,6 +49,7 @@ public class JdbcConnector
private final JdbcRecordSetProvider jdbcRecordSetProvider;
private final JdbcPageSinkProvider jdbcPageSinkProvider;
private final Optional<ConnectorAccessControl> accessControl;
private final Set<Procedure> procedures;

private final ConcurrentMap<ConnectorTransactionHandle, JdbcMetadata> transactions = new ConcurrentHashMap<>();

Expand All @@ -56,14 +60,16 @@ public JdbcConnector(
JdbcSplitManager jdbcSplitManager,
JdbcRecordSetProvider jdbcRecordSetProvider,
JdbcPageSinkProvider jdbcPageSinkProvider,
Optional<ConnectorAccessControl> accessControl)
Optional<ConnectorAccessControl> accessControl,
Set<Procedure> procedures)
{
this.lifeCycleManager = requireNonNull(lifeCycleManager, "lifeCycleManager is null");
this.jdbcMetadataFactory = requireNonNull(jdbcMetadataFactory, "jdbcMetadataFactory is null");
this.jdbcSplitManager = requireNonNull(jdbcSplitManager, "jdbcSplitManager is null");
this.jdbcRecordSetProvider = requireNonNull(jdbcRecordSetProvider, "jdbcRecordSetProvider is null");
this.jdbcPageSinkProvider = requireNonNull(jdbcPageSinkProvider, "jdbcPageSinkProvider is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
this.procedures = ImmutableSet.copyOf(requireNonNull(procedures, "procedures is null"));
}

@Override
Expand Down Expand Up @@ -127,6 +133,12 @@ public ConnectorAccessControl getAccessControl()
return accessControl.orElseThrow(UnsupportedOperationException::new);
}

@Override
public Set<Procedure> getProcedures()
{
return procedures;
}

@Override
public final void shutdown()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import com.google.inject.Module;
import com.google.inject.Scopes;
import io.prestosql.spi.connector.ConnectorAccessControl;
import io.prestosql.spi.procedure.Procedure;

import static com.google.inject.multibindings.Multibinder.newSetBinder;
import static com.google.inject.multibindings.OptionalBinder.newOptionalBinder;
import static io.airlift.configuration.ConfigBinder.configBinder;
import static java.util.Objects.requireNonNull;
Expand All @@ -36,6 +38,7 @@ public JdbcModule(String connectorId)
public void configure(Binder binder)
{
newOptionalBinder(binder, ConnectorAccessControl.class);
newSetBinder(binder, Procedure.class);
binder.bind(JdbcConnectorId.class).toInstance(new JdbcConnectorId(connectorId));
binder.bind(JdbcMetadataFactory.class).in(Scopes.SINGLETON);
binder.bind(JdbcSplitManager.class).in(Scopes.SINGLETON);
Expand Down