diff --git a/be/src/vec/runtime/vfile_result_writer.cpp b/be/src/vec/runtime/vfile_result_writer.cpp index 96f11256b96a93..a695e1f37f3ea8 100644 --- a/be/src/vec/runtime/vfile_result_writer.cpp +++ b/be/src/vec/runtime/vfile_result_writer.cpp @@ -434,12 +434,12 @@ Status VFileResultWriter::_create_new_file_if_exceed_size() { Status VFileResultWriter::_close_file_writer(bool done, bool only_close) { if (_vfile_writer) { - _vfile_writer->close(); // we can not use _current_written_bytes to COUNTER_UPDATE(_written_data_bytes, _current_written_bytes) // because it will call `write()` function of orc/parquet function in `_vfile_writer->close()` // and the real written_len will increase // and _current_written_bytes will less than _vfile_writer->written_len() COUNTER_UPDATE(_written_data_bytes, _vfile_writer->written_len()); + _vfile_writer->close(); _vfile_writer.reset(nullptr); } else if (_file_writer_impl) { _file_writer_impl->close(); diff --git a/be/src/vec/runtime/vorc_writer.cpp b/be/src/vec/runtime/vorc_writer.cpp index b98de180e40e9b..5bf6c3aa7aebf0 100644 --- a/be/src/vec/runtime/vorc_writer.cpp +++ b/be/src/vec/runtime/vorc_writer.cpp @@ -92,13 +92,22 @@ std::unique_ptr VOrcWriterWrapper::_create_row_batch(siz } int64_t VOrcWriterWrapper::written_len() { - return _output_stream->getLength(); + // written_len() will be called in VFileResultWriter::_close_file_writer + // but _output_stream may be nullptr + // because the failure built by _schema in open() + if (_output_stream) { + return _output_stream->getLength(); + } + return 0; } void VOrcWriterWrapper::close() { if (_writer != nullptr) { _writer->close(); } + if (_output_stream) { + _output_stream->close(); + } } #define RETURN_WRONG_TYPE \