public static Path getTableDefaultLocation(HdfsContext context, SemiTransactionalHiveMetastore metastore, HdfsEnvironment hdfsEnvironment, String schemaName, String tableName) { Optional<String> location = getDatabase(metastore, schemaName).getLocation(); if (!location.isPresent() || location.get().isEmpty()) { throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format("Database '%s' location is not set", schemaName)); } Path databasePath = new Path(location.get()); if (!isS3FileSystem(context, hdfsEnvironment, databasePath)) { if (!pathExists(context, hdfsEnvironment, databasePath)) { throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format("Database '%s' location does not exist: %s", schemaName, databasePath)); } if (!isDirectory(context, hdfsEnvironment, databasePath)) { throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format("Database '%s' location is not a directory: %s", schemaName, databasePath)); } } return new Path(databasePath, tableName); }
@Override public void createDatabase(Database database) { if (!database.getLocation().isPresent() && defaultDir.isPresent()) { String databaseLocation = new Path(defaultDir.get(), database.getDatabaseName()).toString(); database = Database.builder(database) .setLocation(Optional.of(databaseLocation)) .build(); } try { DatabaseInput databaseInput = GlueInputConverter.convertDatabase(database); glueClient.createDatabase(new CreateDatabaseRequest().withDatabaseInput(databaseInput)); } catch (AlreadyExistsException e) { throw new SchemaAlreadyExistsException(database.getDatabaseName()); } catch (AmazonServiceException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } if (database.getLocation().isPresent()) { HiveWriteUtils.createDirectory(hdfsContext, hdfsEnvironment, new Path(database.getLocation().get())); } }
public static DatabaseInput convertDatabase(Database database) { DatabaseInput input = new DatabaseInput(); input.setName(database.getDatabaseName()); input.setParameters(database.getParameters()); database.getComment().ifPresent(input::setDescription); database.getLocation().ifPresent(input::setLocationUri); return input; }
@Override public synchronized void createDatabase(Database database) { requireNonNull(database, "database is null"); if (database.getLocation().isPresent()) { throw new PrestoException(HIVE_METASTORE_ERROR, "Database can not be created with a location set"); } verifyDatabaseNotExists(database.getDatabaseName()); Path databaseMetadataDirectory = getDatabaseMetadataDirectory(database.getDatabaseName()); writeSchemaFile("database", databaseMetadataDirectory, databaseCodec, new DatabaseMetadata(database), false); }
@Test public void testConvertDatabase() { com.facebook.presto.hive.metastore.Database prestoDb = GlueToPrestoConverter.convertDatabase(testDb); assertEquals(prestoDb.getDatabaseName(), testDb.getName()); assertEquals(prestoDb.getLocation().get(), testDb.getLocationUri()); assertEquals(prestoDb.getComment().get(), testDb.getDescription()); assertEquals(prestoDb.getParameters(), testDb.getParameters()); assertEquals(prestoDb.getOwnerName(), PUBLIC_OWNER); assertEquals(prestoDb.getOwnerType(), PrincipalType.ROLE); }
public static org.apache.hadoop.hive.metastore.api.Database toMetastoreApiDatabase(Database database) { org.apache.hadoop.hive.metastore.api.Database result = new org.apache.hadoop.hive.metastore.api.Database(); result.setName(database.getDatabaseName()); database.getLocation().ifPresent(result::setLocationUri); result.setOwnerName(database.getOwnerName()); result.setOwnerType(toMetastoreApiPrincipalType(database.getOwnerType())); database.getComment().ifPresent(result::setDescription); result.setParameters(database.getParameters()); return result; }
@Test public void testConvertDatabase() { DatabaseInput dbInput = GlueInputConverter.convertDatabase(testDb); assertEquals(dbInput.getName(), testDb.getDatabaseName()); assertEquals(dbInput.getDescription(), testDb.getComment().get()); assertEquals(dbInput.getLocationUri(), testDb.getLocation().get()); assertEquals(dbInput.getParameters(), testDb.getParameters()); }
@Test public void testConvertDatabase() { DatabaseInput dbInput = GlueInputConverter.convertDatabase(testDb); assertEquals(dbInput.getName(), testDb.getDatabaseName()); assertEquals(dbInput.getDescription(), testDb.getComment().get()); assertEquals(dbInput.getLocationUri(), testDb.getLocation().get()); assertEquals(dbInput.getParameters(), testDb.getParameters()); }
@Test public void testConvertDatabase() { com.facebook.presto.hive.metastore.Database prestoDb = GlueToPrestoConverter.convertDatabase(testDb); assertEquals(prestoDb.getDatabaseName(), testDb.getName()); assertEquals(prestoDb.getLocation().get(), testDb.getLocationUri()); assertEquals(prestoDb.getComment().get(), testDb.getDescription()); assertEquals(prestoDb.getParameters(), testDb.getParameters()); assertEquals(prestoDb.getOwnerName(), PUBLIC_OWNER); assertEquals(prestoDb.getOwnerType(), PrincipalType.ROLE); }