Skip to content

Commit

Permalink
Pass schema type to FileHiveMetastore.getSchemaPath and its callers
Browse files Browse the repository at this point in the history
  • Loading branch information
jirassimok authored and findepi committed Dec 20, 2021
1 parent a782eff commit 086b2f9
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public synchronized void dropDatabase(HiveIdentity identity, String databaseName
throw new TrinoException(HIVE_METASTORE_ERROR, "Database " + databaseName + " is not empty");
}

deleteMetadataDirectory(getDatabaseMetadataDirectory(databaseName));
deleteMetadataDirectory(DATABASE, getDatabaseMetadataDirectory(databaseName));
}

@Override
Expand Down Expand Up @@ -280,7 +280,7 @@ private void verifyDatabaseNotExists(String databaseName)
@Override
public synchronized List<String> getAllDatabases()
{
List<String> databases = getChildSchemaDirectories(catalogDirectory).stream()
List<String> databases = getChildSchemaDirectories(DATABASE, catalogDirectory).stream()
.map(Path::getName)
.collect(toList());
return ImmutableList.copyOf(databases);
Expand Down Expand Up @@ -492,7 +492,7 @@ private List<String> listAllTables(String databaseName)
}

Path databaseMetadataDirectory = getDatabaseMetadataDirectory(databaseName);
List<String> tables = getChildSchemaDirectories(databaseMetadataDirectory).stream()
List<String> tables = getChildSchemaDirectories(TABLE, databaseMetadataDirectory).stream()
.map(Path::getName)
.collect(toImmutableList());
return tables;
Expand Down Expand Up @@ -522,7 +522,7 @@ public synchronized void dropTable(HiveIdentity identity, String databaseName, S

// It is safe to delete the whole meta directory for external tables and views
if (!table.getTableType().equals(MANAGED_TABLE.name()) || deleteData) {
deleteMetadataDirectory(tableMetadataDirectory);
deleteMetadataDirectory(TABLE, tableMetadataDirectory);
}
else {
// in this case we only want to delete the metadata of a managed table
Expand Down Expand Up @@ -576,7 +576,7 @@ public synchronized void renameTable(HiveIdentity identity, String databaseName,
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not create new table directory");
}
// Iceberg metadata references files in old path, so these cannot be moved. Moving table description (metadata from metastore perspective) only.
if (!metadataFileSystem.rename(getSchemaPath(oldPath), getSchemaPath(newPath))) {
if (!metadataFileSystem.rename(getSchemaPath(TABLE, oldPath), getSchemaPath(TABLE, newPath))) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not rename table schema file");
}
// TODO drop data files when table is being dropped
Expand Down Expand Up @@ -734,7 +734,7 @@ public synchronized void addPartitions(HiveIdentity identity, String databaseNam
Partition partition = partitionWithStatistics.getPartition();
verifiedPartition(table, partition);
Path partitionMetadataDirectory = getPartitionMetadataDirectory(table, partition.getValues());
Path schemaPath = getSchemaPath(partitionMetadataDirectory);
Path schemaPath = getSchemaPath(PARTITION, partitionMetadataDirectory);
if (metadataFileSystem.exists(schemaPath)) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Partition already exists");
}
Expand Down Expand Up @@ -814,7 +814,7 @@ public synchronized void dropPartition(HiveIdentity identity, String databaseNam

Path partitionMetadataDirectory = getPartitionMetadataDirectory(table, partitionValues);
if (deleteData) {
deleteMetadataDirectory(partitionMetadataDirectory);
deleteMetadataDirectory(PARTITION, partitionMetadataDirectory);
}
else {
deleteSchemaFile(PARTITION, partitionMetadataDirectory);
Expand Down Expand Up @@ -1015,7 +1015,7 @@ private synchronized Optional<List<String>> getAllPartitionNames(HiveIdentity id
private boolean isValidPartition(Table table, String partitionName)
{
try {
return metadataFileSystem.exists(getSchemaPath(getPartitionMetadataDirectory(table, partitionName)));
return metadataFileSystem.exists(getSchemaPath(PARTITION, getPartitionMetadataDirectory(table, partitionName)));
}
catch (IOException e) {
return false;
Expand Down Expand Up @@ -1185,7 +1185,7 @@ private synchronized void deleteTablePrivileges(Table table)
}
}

private List<Path> getChildSchemaDirectories(Path metadataDirectory)
private List<Path> getChildSchemaDirectories(SchemaType type, Path metadataDirectory)
{
try {
if (!metadataFileSystem.isDirectory(metadataDirectory)) {
Expand All @@ -1201,7 +1201,7 @@ private List<Path> getChildSchemaDirectories(Path metadataDirectory)
if (childPath.getName().startsWith(".")) {
continue;
}
if (metadataFileSystem.isFile(getSchemaPath(childPath))) {
if (metadataFileSystem.isFile(getSchemaPath(type, childPath))) {
childSchemaDirectories.add(childPath);
}
}
Expand Down Expand Up @@ -1233,10 +1233,10 @@ private Set<HivePrivilegeInfo> readAllPermissions(Path permissionsDirectory)
}
}

private void deleteMetadataDirectory(Path metadataDirectory)
private void deleteMetadataDirectory(SchemaType type, Path metadataDirectory)
{
try {
Path schemaPath = getSchemaPath(metadataDirectory);
Path schemaPath = getSchemaPath(type, metadataDirectory);
if (!metadataFileSystem.isFile(schemaPath)) {
// if there is no schema file, assume this is not a database, partition or table
return;
Expand Down Expand Up @@ -1273,7 +1273,7 @@ private void checkVersion(Optional<String> writerVersion)

private <T> Optional<T> readSchemaFile(SchemaType type, Path metadataDirectory, JsonCodec<T> codec)
{
return readFile(type + " schema", getSchemaPath(metadataDirectory), codec);
return readFile(type + " schema", getSchemaPath(type, metadataDirectory), codec);
}

private <T> Optional<T> readFile(String type, Path path, JsonCodec<T> codec)
Expand All @@ -1295,7 +1295,7 @@ private <T> Optional<T> readFile(String type, Path path, JsonCodec<T> codec)

private <T> void writeSchemaFile(SchemaType type, Path directory, JsonCodec<T> codec, T value, boolean overwrite)
{
writeFile(type + " schema", getSchemaPath(directory), codec, value, overwrite);
writeFile(type + " schema", getSchemaPath(type, directory), codec, value, overwrite);
}

private <T> void writeFile(String type, Path path, JsonCodec<T> codec, T value, boolean overwrite)
Expand Down Expand Up @@ -1324,7 +1324,7 @@ private <T> void writeFile(String type, Path path, JsonCodec<T> codec, T value,
private void deleteSchemaFile(SchemaType type, Path metadataDirectory)
{
try {
if (!metadataFileSystem.delete(getSchemaPath(metadataDirectory), false)) {
if (!metadataFileSystem.delete(getSchemaPath(type, metadataDirectory), false)) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not delete " + type + " schema");
}
}
Expand Down Expand Up @@ -1380,7 +1380,7 @@ private Path getRoleGrantsFile()
return new Path(catalogDirectory, ROLE_GRANTS_FILE_NAME);
}

private static Path getSchemaPath(Path metadataDirectory)
private static Path getSchemaPath(SchemaType type, Path metadataDirectory)
{
return new Path(metadataDirectory, TRINO_SCHEMA_FILE_NAME);
}
Expand Down

0 comments on commit 086b2f9

Please sign in to comment.