Search in sources :

Example 16 with Database

use of io.trino.plugin.hive.metastore.Database in project trino by trinodb.

the class TestIcebergProjectionPushdownPlans method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    Session session = testSessionBuilder().setCatalog(CATALOG).setSchema(SCHEMA).build();
    metastoreDir = Files.createTempDir();
    HiveMetastore metastore = createTestingFileHiveMetastore(metastoreDir);
    LocalQueryRunner queryRunner = LocalQueryRunner.create(session);
    queryRunner.createCatalog(CATALOG, new TestingIcebergConnectorFactory(Optional.of(metastore), Optional.empty(), EMPTY_MODULE), ImmutableMap.of());
    Database database = Database.builder().setDatabaseName(SCHEMA).setOwnerName(Optional.of("public")).setOwnerType(Optional.of(PrincipalType.ROLE)).build();
    metastore.createDatabase(database);
    return queryRunner;
}
Also used : HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) FileHiveMetastore.createTestingFileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore.createTestingFileHiveMetastore) Database(io.trino.plugin.hive.metastore.Database) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session)

Example 17 with Database

use of io.trino.plugin.hive.metastore.Database in project trino by trinodb.

the class FileHiveMetastore method setDatabaseOwner.

@Override
public synchronized void setDatabaseOwner(String databaseName, HivePrincipal principal) {
    Database database = getRequiredDatabase(databaseName);
    Path databaseMetadataDirectory = getDatabaseMetadataDirectory(database.getDatabaseName());
    Database newDatabase = Database.builder(database).setOwnerName(Optional.of(principal.getName())).setOwnerType(Optional.of(principal.getType())).build();
    writeSchemaFile(DATABASE, databaseMetadataDirectory, databaseCodec, new DatabaseMetadata(currentVersion, newDatabase), true);
}
Also used : Path(org.apache.hadoop.fs.Path) Database(io.trino.plugin.hive.metastore.Database)

Example 18 with Database

use of io.trino.plugin.hive.metastore.Database in project trino by trinodb.

the class TrinoHiveCatalog method defaultTableLocation.

@Override
public String defaultTableLocation(ConnectorSession session, SchemaTableName schemaTableName) {
    Database database = metastore.getDatabase(schemaTableName.getSchemaName()).orElseThrow(() -> new SchemaNotFoundException(schemaTableName.getSchemaName()));
    String tableNameForLocation = createNewTableName(schemaTableName.getTableName());
    return getTableDefaultLocation(database, new HdfsEnvironment.HdfsContext(session), hdfsEnvironment, schemaTableName.getSchemaName(), tableNameForLocation).toString();
}
Also used : Database(io.trino.plugin.hive.metastore.Database) SchemaNotFoundException(io.trino.spi.connector.SchemaNotFoundException) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext)

Example 19 with Database

use of io.trino.plugin.hive.metastore.Database in project trino by trinodb.

the class TestConnectorPushdownRulesWithHive method createLocalQueryRunner.

@Override
protected Optional<LocalQueryRunner> createLocalQueryRunner() {
    baseDir = Files.createTempDir();
    HdfsConfig config = new HdfsConfig();
    HdfsConfiguration configuration = new HiveHdfsConfiguration(new HdfsConfigurationInitializer(config), ImmutableSet.of());
    HdfsEnvironment environment = new HdfsEnvironment(configuration, config, new NoHdfsAuthentication());
    metastore = new FileHiveMetastore(new NodeVersion("test_version"), environment, new MetastoreConfig(), new FileHiveMetastoreConfig().setCatalogDirectory(baseDir.toURI().toString()).setMetastoreUser("test"));
    Database database = Database.builder().setDatabaseName(SCHEMA_NAME).setOwnerName(Optional.of("public")).setOwnerType(Optional.of(PrincipalType.ROLE)).build();
    metastore.createDatabase(database);
    LocalQueryRunner queryRunner = LocalQueryRunner.create(HIVE_SESSION);
    queryRunner.createCatalog(HIVE_CATALOG_NAME, new TestingHiveConnectorFactory(metastore), ImmutableMap.of());
    return Optional.of(queryRunner);
}
Also used : HdfsConfigurationInitializer(io.trino.plugin.hive.HdfsConfigurationInitializer) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) HdfsConfig(io.trino.plugin.hive.HdfsConfig) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) HdfsConfiguration(io.trino.plugin.hive.HdfsConfiguration) NoHdfsAuthentication(io.trino.plugin.hive.authentication.NoHdfsAuthentication) LocalQueryRunner(io.trino.testing.LocalQueryRunner) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) NodeVersion(io.trino.plugin.hive.NodeVersion) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) TestingHiveConnectorFactory(io.trino.plugin.hive.TestingHiveConnectorFactory) Database(io.trino.plugin.hive.metastore.Database)

Example 20 with Database

use of io.trino.plugin.hive.metastore.Database in project trino by trinodb.

the class TestProtoUtils method testDatabaseNameLocation.

@Test
public void testDatabaseNameLocation() {
    Database db = ProtoUtils.fromProto(TestingAlluxioMetastoreObjects.getTestingDatabase().build());
    assertEquals(TestingAlluxioMetastoreObjects.DATABASE_NAME, db.getDatabaseName());
    assertEquals("alluxio:///", db.getLocation().get());
    // Intentionally leave location unset
    alluxio.grpc.table.Database.Builder alluxioDb = TestingAlluxioMetastoreObjects.getTestingDatabase().clearLocation();
    assertEquals(Optional.empty(), ProtoUtils.fromProto(alluxioDb.build()).getLocation());
}
Also used : Database(io.trino.plugin.hive.metastore.Database) Test(org.testng.annotations.Test)

Aggregations

Database (io.trino.plugin.hive.metastore.Database)20 TrinoException (io.trino.spi.TrinoException)8 Path (org.apache.hadoop.fs.Path)7 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)6 SchemaNotFoundException (io.trino.spi.connector.SchemaNotFoundException)6 HdfsEnvironment (io.trino.plugin.hive.HdfsEnvironment)5 HiveMetastore (io.trino.plugin.hive.metastore.HiveMetastore)4 MetastoreConfig (io.trino.plugin.hive.metastore.MetastoreConfig)4 LocalQueryRunner (io.trino.testing.LocalQueryRunner)4 IOException (java.io.IOException)4 HdfsConfig (io.trino.plugin.hive.HdfsConfig)3 HdfsConfiguration (io.trino.plugin.hive.HdfsConfiguration)3 HdfsConfigurationInitializer (io.trino.plugin.hive.HdfsConfigurationInitializer)3 HiveHdfsConfiguration (io.trino.plugin.hive.HiveHdfsConfiguration)3 NodeVersion (io.trino.plugin.hive.NodeVersion)3 NoHdfsAuthentication (io.trino.plugin.hive.authentication.NoHdfsAuthentication)3 FileHiveMetastore (io.trino.plugin.hive.metastore.file.FileHiveMetastore)3 FileHiveMetastoreConfig (io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2