Skip to content

Conversation

@loustler
Copy link
Contributor

@loustler loustler commented Aug 22, 2024

Purpose of this pull request

Refactor S3FileCatalog and S3FileCatalogFactory, it's logic exactly same with AbstractFileCatalog

public abstract class AbstractFileCatalog implements Catalog {
protected final String catalogName;
private final HadoopFileSystemProxy hadoopFileSystemProxy;
private final String filePath;
protected AbstractFileCatalog(
HadoopFileSystemProxy hadoopFileSystemProxy, String filePath, String catalogName) {
this.catalogName = catalogName;
this.filePath = filePath;
this.hadoopFileSystemProxy = hadoopFileSystemProxy;
}
@Override
public void open() throws CatalogException {}
@Override
public void close() throws CatalogException {}
@Override
public String name() {
return catalogName;
}
@Override
public String getDefaultDatabase() throws CatalogException {
return null;
}
@Override
public boolean databaseExists(String databaseName) throws CatalogException {
return false;
}
@Override
public List<String> listDatabases() throws CatalogException {
return null;
}
@Override
public List<String> listTables(String databaseName)
throws CatalogException, DatabaseNotExistException {
return null;
}
@SneakyThrows
@Override
public boolean tableExists(TablePath tablePath) throws CatalogException {
return hadoopFileSystemProxy.fileExist(filePath);
}
@Override
public CatalogTable getTable(TablePath tablePath)
throws CatalogException, TableNotExistException {
return null;
}
@SneakyThrows
@Override
public void createTable(TablePath tablePath, CatalogTable table, boolean ignoreIfExists)
throws TableAlreadyExistException, DatabaseNotExistException, CatalogException {
hadoopFileSystemProxy.createDir(filePath);
}
@SneakyThrows
@Override
public void dropTable(TablePath tablePath, boolean ignoreIfNotExists)
throws TableNotExistException, CatalogException {
hadoopFileSystemProxy.deleteFile(filePath);
}
@Override
public void createDatabase(TablePath tablePath, boolean ignoreIfExists)
throws DatabaseAlreadyExistException, CatalogException {}
@Override
public void dropDatabase(TablePath tablePath, boolean ignoreIfNotExists)
throws DatabaseNotExistException, CatalogException {}
@SneakyThrows
@Override
public void truncateTable(TablePath tablePath, boolean ignoreIfNotExists)
throws TableNotExistException, CatalogException {
hadoopFileSystemProxy.deleteFile(filePath);
hadoopFileSystemProxy.createDir(filePath);
}
@SneakyThrows
@Override
public boolean isExistsData(TablePath tablePath) {
final List<LocatedFileStatus> locatedFileStatuses =
hadoopFileSystemProxy.listFile(filePath);
return CollectionUtils.isNotEmpty(locatedFileStatuses);
}

Does this PR introduce any user-facing change?

Nothing

How was this patch tested?

No need tests I think. It's enough already written tests.

Check list

@Hisoka-X Hisoka-X changed the title Refactor S3FileCatalog and it's factory [Improve] Refactor S3FileCatalog and it's factory Aug 22, 2024
Copy link
Member

@Hisoka-X Hisoka-X left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @loustler !

@hailin0 hailin0 merged commit d928e8b into apache:dev Aug 23, 2024
@loustler loustler deleted the improve/s3-file-catalog branch August 23, 2024 05:36
hawk9821 pushed a commit to hawk9821/seatunnel that referenced this pull request Aug 29, 2024
hawk9821 pushed a commit to hawk9821/seatunnel that referenced this pull request Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants