Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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<String, List<Integer>> deviceColumnIndices = new HashMap<>();
Expand All @@ -483,16 +485,19 @@ public static void writeWithTablets(SessionDataSet sessionDataSet, String filePa

List<Tablet> 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(
Expand Down