Skip to content

Commit

Permalink
Manage catalog and metastore together in Iceberg modules
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Oct 15, 2021
1 parent 44569a4 commit 8a59a45
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Scopes;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.cache.CachingHiveMetastore;
import io.trino.plugin.hive.metastore.cache.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.cache.ForCachingHiveMetastore;
import io.trino.plugin.hive.metastore.file.FileMetastoreModule;
import io.trino.plugin.hive.metastore.thrift.ThriftMetastoreModule;
import io.trino.plugin.iceberg.catalog.file.IcebergFileMetastoreCatalogModule;
import io.trino.plugin.iceberg.catalog.hms.IcebergHiveMetastoreCatalogModule;

import javax.inject.Inject;

Expand All @@ -32,12 +33,12 @@
import static io.trino.plugin.iceberg.CatalogType.TESTING_FILE_METASTORE;
import static java.util.Objects.requireNonNull;

public class IcebergMetastoreModule
public class IcebergCatalogModule
extends AbstractConfigurationAwareModule
{
private final Optional<HiveMetastore> metastore;

public IcebergMetastoreModule(Optional<HiveMetastore> metastore)
public IcebergCatalogModule(Optional<HiveMetastore> metastore)
{
this.metastore = requireNonNull(metastore, "metastore is null");
}
Expand All @@ -48,10 +49,11 @@ protected void setup(Binder binder)
if (metastore.isPresent()) {
binder.bind(HiveMetastore.class).annotatedWith(ForCachingHiveMetastore.class).toInstance(metastore.get());
install(new CachingHiveMetastoreModule());
binder.bind(HiveTableOperationsProvider.class).in(Scopes.SINGLETON);
}
else {
bindMetastoreModule(HIVE_METASTORE, new ThriftMetastoreModule());
bindMetastoreModule(TESTING_FILE_METASTORE, new FileMetastoreModule());
bindCatalogModule(HIVE_METASTORE, new IcebergHiveMetastoreCatalogModule());
bindCatalogModule(TESTING_FILE_METASTORE, new IcebergFileMetastoreCatalogModule());
// TODO add support for Glue metastore
}

Expand All @@ -69,7 +71,7 @@ public MetastoreValidator(HiveMetastore metastore)
}
}

private void bindMetastoreModule(CatalogType catalogType, Module module)
private void bindCatalogModule(CatalogType catalogType, Module module)
{
install(conditionalModule(
IcebergConfig.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ public void configure(Binder binder)
binder.bind(FileFormatDataSourceStats.class).in(Scopes.SINGLETON);
newExporter(binder).export(FileFormatDataSourceStats.class).withGeneratedName();

// TODO inject table operations based on IcebergConfig.getCatalogType
binder.bind(HiveTableOperationsProvider.class).in(Scopes.SINGLETON);

binder.bind(IcebergFileWriterFactory.class).in(Scopes.SINGLETON);
newExporter(binder).export(IcebergFileWriterFactory.class).withGeneratedName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static Connector createConnector(
new ConnectorObjectNameGeneratorModule(catalogName, "io.trino.plugin.iceberg", "trino.plugin.iceberg"),
new JsonModule(),
new IcebergModule(),
new IcebergMetastoreModule(metastore),
new IcebergCatalogModule(metastore),
new HiveHdfsModule(),
new HiveS3Module(),
new HiveGcsModule(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.iceberg.catalog.file;

import com.google.inject.Binder;
import com.google.inject.Scopes;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.trino.plugin.hive.metastore.file.FileMetastoreModule;
import io.trino.plugin.iceberg.HiveTableOperationsProvider;

public class IcebergFileMetastoreCatalogModule
extends AbstractConfigurationAwareModule
{
@Override
protected void setup(Binder binder)
{
install(new FileMetastoreModule());

// TODO inject table operations based on IcebergConfig.getCatalogType
binder.bind(HiveTableOperationsProvider.class).in(Scopes.SINGLETON);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.iceberg.catalog.hms;

import com.google.inject.Binder;
import com.google.inject.Scopes;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.trino.plugin.hive.metastore.thrift.ThriftMetastoreModule;
import io.trino.plugin.iceberg.HiveTableOperationsProvider;

public class IcebergHiveMetastoreCatalogModule
extends AbstractConfigurationAwareModule
{
@Override
protected void setup(Binder binder)
{
install(new ThriftMetastoreModule());

// TODO inject table operations based on IcebergConfig.getCatalogType
binder.bind(HiveTableOperationsProvider.class).in(Scopes.SINGLETON);
}
}

0 comments on commit 8a59a45

Please sign in to comment.