optimize buffer allocated logic

This commit is contained in:
fariel 2021-07-23 14:38:43 +08:00
parent fd42a23b68
commit f9391a78e7

View File

@ -106,7 +106,7 @@ public class DorisStreamLoadVisitor {
} }
if (DorisWriterOptions.StreamLoadFormat.JSON.equals(writerOptions.getStreamLoadFormat())) { if (DorisWriterOptions.StreamLoadFormat.JSON.equals(writerOptions.getStreamLoadFormat())) {
ByteBuffer bos = ByteBuffer.allocate(totalBytes + rows.size() + 1); ByteBuffer bos = ByteBuffer.allocate(totalBytes + (rows.isEmpty() ? 2 : rows.size() + 1));
bos.put("[".getBytes(StandardCharsets.UTF_8)); bos.put("[".getBytes(StandardCharsets.UTF_8));
byte[] jsonDelimiter = ",".getBytes(StandardCharsets.UTF_8); byte[] jsonDelimiter = ",".getBytes(StandardCharsets.UTF_8);
boolean isFirstElement = true; boolean isFirstElement = true;