diff --git a/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java b/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java index 5994d4d554eea..7701bb1f973dc 100644 --- a/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java @@ -98,7 +98,7 @@ protected void testOnWindows() throws IOException { "exit", "%^errorlevel%"); builder.environment().put("CLASSPATH", libPath); - testOutput(builder, output, 1); + testOutput(builder, output, 0); prepareData(); @@ -148,7 +148,7 @@ protected void testOnUnix() throws IOException { "-q", "select * from root.**"); builder.environment().put("CLASSPATH", libPath); - testOutput(builder, output, 1); + testOutput(builder, output, 0); prepareData(); diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/tsfile/ExportTsFile.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/tsfile/ExportTsFile.java index 7981b6ec84c72..2874a99520323 100644 --- a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/tsfile/ExportTsFile.java +++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/tsfile/ExportTsFile.java @@ -337,9 +337,11 @@ private static void dumpResult(String sql, int index) { final String path = targetDirectory + targetFile + index + ".tsfile"; try (SessionDataSet sessionDataSet = session.executeQueryStatement(sql, timeout)) { long start = System.currentTimeMillis(); - writeWithTablets(sessionDataSet, path); - long end = System.currentTimeMillis(); - ioTPrinter.println("Export completely!cost: " + (end - start) + " ms."); + boolean isComplete = writeWithTablets(sessionDataSet, path); + if (isComplete) { + long end = System.currentTimeMillis(); + ioTPrinter.println("Export completely!cost: " + (end - start) + " ms."); + } } catch (StatementExecutionException | IoTDBConnectionException | IOException @@ -460,7 +462,7 @@ private static void writeWithTablets( "squid:S3776", "squid:S6541" }) // Suppress high Cognitive Complexity warning, Suppress many task in one method warning - public static void writeWithTablets(SessionDataSet sessionDataSet, String filePath) + public static Boolean writeWithTablets(SessionDataSet sessionDataSet, String filePath) throws IOException, IoTDBConnectionException, StatementExecutionException, @@ -471,7 +473,7 @@ public static void writeWithTablets(SessionDataSet sessionDataSet, String filePa if (f.exists()) { Files.delete(f.toPath()); } - + boolean isEmpty = false; try (TsFileWriter tsFileWriter = new TsFileWriter(f)) { // device -> column indices in columnNames Map> deviceColumnIndices = new HashMap<>(); @@ -483,16 +485,19 @@ public static void writeWithTablets(SessionDataSet sessionDataSet, String filePa List tabletList = constructTablets(deviceSchemaMap, alignedDevices, tsFileWriter); - if (tabletList.isEmpty()) { - ioTPrinter.println("!!!Warning:Tablet is empty,no data can be exported."); - System.exit(CODE_ERROR); + if (!tabletList.isEmpty()) { + writeWithTablets( + sessionDataSet, tabletList, alignedDevices, tsFileWriter, deviceColumnIndices); + tsFileWriter.flushAllChunkGroups(); + } else { + isEmpty = true; } - - writeWithTablets( - sessionDataSet, tabletList, alignedDevices, tsFileWriter, deviceColumnIndices); - - tsFileWriter.flushAllChunkGroups(); } + if (isEmpty) { + ioTPrinter.println("!!!Warning:Tablet is empty,no data can be exported."); + return false; + } + return true; } private static void writeToTsFile(