Skip to content

Commit

Permalink
fix(data-transfer): fix several data-transfer bugs (#3288)
Browse files Browse the repository at this point in the history
* fix(resultset-export): the exported file is empty if use lower table name for oracle mode (#3254)

* convert to upper case for oracle

* fix typo

* use lower case for mysql mode

* list directory instead of looking up by name

* change sequence version to 4.1.0

* change incorrect block size
  • Loading branch information
LuckyPickleZZ authored Sep 6, 2024
1 parent 52a32ce commit 3c0c66e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ public ResultSetExportResult call() throws Exception {
*/
File origin = new File(localResultSetFilePath);
if (!origin.exists()) {
LOGGER.warn("There is no file generated, create an empty file instead.");
FileUtils.touch(origin);
}

/*
* OBDumper 不支持 excel 导出,需要先生成 csv, 然后使用工具类转换成 xlsx
*/
if (DataTransferFormat.EXCEL == parameter.getFileFormat()) {
String excelFilePath = getDumpFileDirectory() + getFileName(DataTransferFormat.EXCEL.getExtension());
String excelFilePath = getDumpFileDirectory() + fileName;
try {
FileConvertUtils.convertCsvToXls(localResultSetFilePath, excelFilePath,
parameter.isSaveSql() ? Collections.singletonList(parameter.getSql()) : null);
Expand Down Expand Up @@ -295,15 +296,13 @@ private void validateSuccessful(DataTransferTaskResult result) {
private String getDumpFilePath(DataTransferTaskResult result, String extension) throws Exception {
List<URL> exportPaths = result.getDataObjectsInfo().get(0).getExportPaths();
if (CollectionUtils.isEmpty(exportPaths)) {
return Paths.get(getDumpFileDirectory(), getFileName(extension)).toString();
File[] files = new File(getDumpFileDirectory()).listFiles();
Verify.verify(files != null && files.length == 1, "");
return files[0].getPath();
}
return exportPaths.get(0).toURI().getPath();
}

private String getFileName(String extension) {
return parameter.getTableName() + extension;
}

private String getDumpFileDirectory() throws IOException {
File dir = Paths.get(workingDir.getPath(), "data", parameter.getDatabase(), "TABLE").toFile();
if (!dir.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Set<ObjectType> getSupportedObjectTypes(ConnectionInfo connectionInfo) th
try (SingleConnectionDataSource dataSource = ConnectionUtil.getDataSource(connectionInfo, "");
Connection connection = dataSource.getConnection()) {
String dbVersion = PluginUtil.getInformationExtension(connectionInfo).getDBVersion(connection);
if (VersionUtils.isGreaterThanOrEqualsTo(dbVersion, "4.0.0")) {
if (VersionUtils.isGreaterThanOrEqualsTo(dbVersion, "4.1.0")) {
types.add(ObjectType.SEQUENCE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ protected DumpParameter doGenerate(File workingDir) throws IOException {
// The default limit in loader-dumper is 64MB. If there is no limit, set it to -1
long exportFileMaxSize = transferConfig.getExportFileMaxSize();
if (exportFileMaxSize <= 0) {
parameter.setBlockSize(MAX_BLOCK_SIZE_MEGABYTE);
parameter.setBlockSize(
BinarySizeUnit.MB.of(MAX_BLOCK_SIZE_MEGABYTE).convert(BinarySizeUnit.B).getSizeDigit());
} else if (exportFileMaxSize > MAX_BLOCK_SIZE_MEGABYTE) {
throw new IllegalArgumentException(String.format("exportFileMaxSize %s MB has exceeded limit %s MB",
exportFileMaxSize, MAX_BLOCK_SIZE_MEGABYTE));
Expand Down

0 comments on commit 3c0c66e

Please sign in to comment.