Skip to content
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 @@ -15,9 +15,8 @@

public enum CatalogType
{
HIVE,
// TODO: dummy type to pass IcebergConfig test, remove it after adding actual catalog types
UNKNOWN,

TESTING_FILE_METASTORE,
HIVE_METASTORE,
GLUE,
/**/;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import javax.validation.constraints.NotNull;

import static io.trino.plugin.hive.HiveCompressionCodec.GZIP;
import static io.trino.plugin.iceberg.CatalogType.HIVE;
import static io.trino.plugin.iceberg.CatalogType.HIVE_METASTORE;
import static io.trino.plugin.iceberg.IcebergFileFormat.ORC;

public class IcebergConfig
Expand All @@ -32,7 +32,7 @@ public class IcebergConfig
private boolean useFileSizeFromMetadata = true;
private int maxPartitionsPerWriter = 100;
private boolean uniqueTableLocation;
private CatalogType catalogType = HIVE;
private CatalogType catalogType = HIVE_METASTORE;

public CatalogType getCatalogType()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.inject.Module;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.MetastoreTypeConfig;
import io.trino.plugin.hive.metastore.cache.CachingHiveMetastore;
import io.trino.plugin.hive.metastore.cache.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.cache.ForCachingHiveMetastore;
Expand All @@ -29,6 +28,8 @@
import java.util.Optional;

import static io.airlift.configuration.ConditionalModule.conditionalModule;
import static io.trino.plugin.iceberg.CatalogType.HIVE_METASTORE;
import static io.trino.plugin.iceberg.CatalogType.TESTING_FILE_METASTORE;
import static java.util.Objects.requireNonNull;

public class IcebergMetastoreModule
Expand All @@ -49,8 +50,8 @@ protected void setup(Binder binder)
install(new CachingHiveMetastoreModule());
}
else {
bindMetastoreModule("thrift", new ThriftMetastoreModule());
bindMetastoreModule("file", new FileMetastoreModule());
bindMetastoreModule(HIVE_METASTORE, new ThriftMetastoreModule());
bindMetastoreModule(TESTING_FILE_METASTORE, new FileMetastoreModule());
// TODO add support for Glue metastore
}

Expand All @@ -68,11 +69,11 @@ public MetastoreValidator(HiveMetastore metastore)
}
}

private void bindMetastoreModule(String name, Module module)
private void bindMetastoreModule(CatalogType catalogType, Module module)
{
install(conditionalModule(
MetastoreTypeConfig.class,
metastore -> name.equalsIgnoreCase(metastore.getMetastoreType()),
IcebergConfig.class,
config -> config.getCatalogType() == catalogType,
module));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public TrinoCatalogFactory(
public TrinoCatalog create()
{
switch (catalogType) {
case HIVE:
case TESTING_FILE_METASTORE:
case HIVE_METASTORE:
return new TrinoHiveCatalog(catalogName, memoizeMetastore(metastore, 1000), hdfsEnvironment, typeManager, tableOperationsProvider, trinoVersion, isUniqueTableLocation);
case UNKNOWN:
case GLUE:
// TODO not supported yet
throw new TrinoException(NOT_SUPPORTED, "Unknown Trino Iceberg catalog type");
}
throw new TrinoException(NOT_SUPPORTED, "Unsupported Trino Iceberg catalog type " + catalogType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static DistributedQueryRunner createIcebergQueryRunner(

queryRunner.installPlugin(new IcebergPlugin());
connectorProperties = new HashMap<>(ImmutableMap.copyOf(connectorProperties));
connectorProperties.putIfAbsent("hive.metastore", "file");
connectorProperties.putIfAbsent("iceberg.catalog.type", "TESTING_FILE_METASTORE");
connectorProperties.putIfAbsent("hive.metastore.catalog.dir", dataDir.toString());
queryRunner.createCatalog(ICEBERG_CATALOG, "iceberg", connectorProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults;
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;
import static io.trino.plugin.hive.HiveCompressionCodec.GZIP;
import static io.trino.plugin.iceberg.CatalogType.HIVE;
import static io.trino.plugin.iceberg.CatalogType.UNKNOWN;
import static io.trino.plugin.iceberg.CatalogType.GLUE;
import static io.trino.plugin.iceberg.CatalogType.HIVE_METASTORE;
import static io.trino.plugin.iceberg.IcebergFileFormat.ORC;
import static io.trino.plugin.iceberg.IcebergFileFormat.PARQUET;

Expand All @@ -39,7 +39,7 @@ public void testDefaults()
.setUseFileSizeFromMetadata(true)
.setMaxPartitionsPerWriter(100)
.setUniqueTableLocation(false)
.setCatalogType(HIVE));
.setCatalogType(HIVE_METASTORE));
}

@Test
Expand All @@ -51,7 +51,7 @@ public void testExplicitPropertyMappings()
.put("iceberg.use-file-size-from-metadata", "false")
.put("iceberg.max-partitions-per-writer", "222")
.put("iceberg.unique-table-location", "true")
.put("iceberg.catalog.type", "UNKNOWN")
.put("iceberg.catalog.type", "GLUE")
.build();

IcebergConfig expected = new IcebergConfig()
Expand All @@ -60,7 +60,7 @@ public void testExplicitPropertyMappings()
.setUseFileSizeFromMetadata(false)
.setMaxPartitionsPerWriter(222)
.setUniqueTableLocation(true)
.setCatalogType(UNKNOWN);
.setCatalogType(GLUE);

assertFullMapping(properties, expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,41 @@ public void testThriftMetastore()
factory.create(
"test",
Map.of(
"hive.metastore", "thrift",
"iceberg.catalog.type", "HIVE_METASTORE",
"hive.metastore.uri", "thrift://foo:1234"),
new TestingConnectorContext())
.shutdown();
}

@Test
public void testHiveMetastoreRejected()
{
ConnectorFactory factory = getConnectorFactory();

assertThatThrownBy(() -> factory.create(
"test",
Map.of(
"hive.metastore", "thrift",
"hive.metastore.uri", "thrift://foo:1234"),
new TestingConnectorContext()))
.hasMessageContaining("Error: Configuration property 'hive.metastore' was not used");
}

@Test
public void testGlueMetastore()
{
ConnectorFactory factory = getConnectorFactory();

assertThatThrownBy(() -> factory.create(
"test",
Map.of("hive.metastore", "glue"),
Map.of("iceberg.catalog.type", "glue"),
new TestingConnectorContext()))
.hasMessageContaining("Explicit bindings are required and HiveMetastore is not explicitly bound");

assertThatThrownBy(() -> factory.create(
"test",
Map.of(
"hive.metastore", "glue",
"iceberg.catalog.type", "glue",
"hive.metastore.uri", "thrift://foo:1234"),
new TestingConnectorContext()))
.hasMessageContaining("Error: Configuration property 'hive.metastore.uri' was not used");
Expand All @@ -75,7 +89,7 @@ public void testRecordingMetastore()
factory.create(
"test",
Map.of(
"hive.metastore", "thrift",
"iceberg.catalog.type", "HIVE_METASTORE",
"hive.metastore.uri", "thrift://foo:1234",
"hive.metastore-recording-path", "/tmp"),
new TestingConnectorContext())
Expand All @@ -85,7 +99,7 @@ public void testRecordingMetastore()
assertThatThrownBy(() -> factory.create(
"test",
Map.of(
"hive.metastore", "glue",
"iceberg.catalog.type", "glue",
"hive.metastore.glue.region", "us-east-2",
"hive.metastore-recording-path", "/tmp"),
new TestingConnectorContext()))
Expand Down