diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/file/FileHiveMetastore.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/file/FileHiveMetastore.java index db82749fe68d..3a3d6f39c0bd 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/file/FileHiveMetastore.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/file/FileHiveMetastore.java @@ -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 @@ -280,7 +280,7 @@ private void verifyDatabaseNotExists(String databaseName) @Override public synchronized List getAllDatabases() { - List databases = getChildSchemaDirectories(catalogDirectory).stream() + List databases = getChildSchemaDirectories(DATABASE, catalogDirectory).stream() .map(Path::getName) .collect(toList()); return ImmutableList.copyOf(databases); @@ -492,7 +492,7 @@ private List listAllTables(String databaseName) } Path databaseMetadataDirectory = getDatabaseMetadataDirectory(databaseName); - List tables = getChildSchemaDirectories(databaseMetadataDirectory).stream() + List tables = getChildSchemaDirectories(TABLE, databaseMetadataDirectory).stream() .map(Path::getName) .collect(toImmutableList()); return tables; @@ -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 @@ -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 @@ -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"); } @@ -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); @@ -1015,7 +1015,7 @@ private synchronized Optional> 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; @@ -1185,7 +1185,7 @@ private synchronized void deleteTablePrivileges(Table table) } } - private List getChildSchemaDirectories(Path metadataDirectory) + private List getChildSchemaDirectories(SchemaType type, Path metadataDirectory) { try { if (!metadataFileSystem.isDirectory(metadataDirectory)) { @@ -1201,7 +1201,7 @@ private List getChildSchemaDirectories(Path metadataDirectory) if (childPath.getName().startsWith(".")) { continue; } - if (metadataFileSystem.isFile(getSchemaPath(childPath))) { + if (metadataFileSystem.isFile(getSchemaPath(type, childPath))) { childSchemaDirectories.add(childPath); } } @@ -1233,10 +1233,10 @@ private Set 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; @@ -1273,7 +1273,7 @@ private void checkVersion(Optional writerVersion) private Optional readSchemaFile(SchemaType type, Path metadataDirectory, JsonCodec codec) { - return readFile(type + " schema", getSchemaPath(metadataDirectory), codec); + return readFile(type + " schema", getSchemaPath(type, metadataDirectory), codec); } private Optional readFile(String type, Path path, JsonCodec codec) @@ -1295,7 +1295,7 @@ private Optional readFile(String type, Path path, JsonCodec codec) private void writeSchemaFile(SchemaType type, Path directory, JsonCodec codec, T value, boolean overwrite) { - writeFile(type + " schema", getSchemaPath(directory), codec, value, overwrite); + writeFile(type + " schema", getSchemaPath(type, directory), codec, value, overwrite); } private void writeFile(String type, Path path, JsonCodec codec, T value, boolean overwrite) @@ -1324,7 +1324,7 @@ private void writeFile(String type, Path path, JsonCodec 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"); } } @@ -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); }