Skip to content

Commit 97046f9

Browse files
2b3c5112b3c511
andauthored
Encountering empty tablets during batch export of tsfile does not affect subsequent export tasks (apache#14484)
* [To dev/1.3]Support auto mkdirs in ExportData (apache#14378) * Update export script prompt information (apache#14276) * update export script prompt information * update export script prompt information * format --------- Co-authored-by: 2b3c511 <[email protected]> * auto mkdirs in ExportData * update failed description --------- Co-authored-by: 2b3c511 <[email protected]> * Encountering empty tablets during batch export of tsfile does not affect subsequent export tasks * format --------- Co-authored-by: 2b3c511 <[email protected]>
1 parent 1bb5667 commit 97046f9

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected void testOnWindows() throws IOException {
9898
"exit",
9999
"%^errorlevel%");
100100
builder.environment().put("CLASSPATH", libPath);
101-
testOutput(builder, output, 1);
101+
testOutput(builder, output, 0);
102102

103103
prepareData();
104104

@@ -148,7 +148,7 @@ protected void testOnUnix() throws IOException {
148148
"-q",
149149
"select * from root.**");
150150
builder.environment().put("CLASSPATH", libPath);
151-
testOutput(builder, output, 1);
151+
testOutput(builder, output, 0);
152152

153153
prepareData();
154154

iotdb-client/cli/src/main/java/org/apache/iotdb/tool/tsfile/ExportTsFile.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,11 @@ private static void dumpResult(String sql, int index) {
338338
final String path = targetDirectory + targetFile + index + ".tsfile";
339339
try (SessionDataSet sessionDataSet = session.executeQueryStatement(sql, timeout)) {
340340
long start = System.currentTimeMillis();
341-
writeWithTablets(sessionDataSet, path);
342-
long end = System.currentTimeMillis();
343-
ioTPrinter.println("Export completely!cost: " + (end - start) + " ms.");
341+
boolean isComplete = writeWithTablets(sessionDataSet, path);
342+
if (isComplete) {
343+
long end = System.currentTimeMillis();
344+
ioTPrinter.println("Export completely!cost: " + (end - start) + " ms.");
345+
}
344346
} catch (StatementExecutionException
345347
| IoTDBConnectionException
346348
| IOException
@@ -460,7 +462,7 @@ private static void writeWithTablets(
460462
"squid:S3776",
461463
"squid:S6541"
462464
}) // Suppress high Cognitive Complexity warning, Suppress many task in one method warning
463-
public static void writeWithTablets(SessionDataSet sessionDataSet, String filePath)
465+
public static Boolean writeWithTablets(SessionDataSet sessionDataSet, String filePath)
464466
throws IOException,
465467
IoTDBConnectionException,
466468
StatementExecutionException,
@@ -471,7 +473,7 @@ public static void writeWithTablets(SessionDataSet sessionDataSet, String filePa
471473
if (f.exists()) {
472474
Files.delete(f.toPath());
473475
}
474-
476+
boolean isEmpty = false;
475477
try (TsFileWriter tsFileWriter = new TsFileWriter(f)) {
476478
// device -> column indices in columnNames
477479
Map<String, List<Integer>> deviceColumnIndices = new HashMap<>();
@@ -483,16 +485,19 @@ public static void writeWithTablets(SessionDataSet sessionDataSet, String filePa
483485

484486
List<Tablet> tabletList = constructTablets(deviceSchemaMap, alignedDevices, tsFileWriter);
485487

486-
if (tabletList.isEmpty()) {
487-
ioTPrinter.println("!!!Warning:Tablet is empty,no data can be exported.");
488-
System.exit(CODE_ERROR);
488+
if (!tabletList.isEmpty()) {
489+
writeWithTablets(
490+
sessionDataSet, tabletList, alignedDevices, tsFileWriter, deviceColumnIndices);
491+
tsFileWriter.flush();
492+
} else {
493+
isEmpty = true;
489494
}
490-
491-
writeWithTablets(
492-
sessionDataSet, tabletList, alignedDevices, tsFileWriter, deviceColumnIndices);
493-
494-
tsFileWriter.flush();
495495
}
496+
if (isEmpty) {
497+
ioTPrinter.println("!!!Warning:Tablet is empty,no data can be exported.");
498+
return false;
499+
}
500+
return true;
496501
}
497502

498503
private static void writeToTsFile(

0 commit comments

Comments
 (0)