3131#include < utility>
3232
3333#include " common/compiler_util.h" // IWYU pragma: keep
34+ #include " common/config.h"
3435#include " common/consts.h"
3536#include " common/status.h"
3637#include " core/block/block.h"
@@ -312,12 +313,15 @@ Status CsvReader::get_next_block(Block* block, size_t* read_rows, bool* eof) {
312313 }
313314
314315 const int batch_size = std::max (_state->batch_size (), (int )_MIN_BATCH_SIZE);
316+ const int64_t max_block_bytes = config::csv_reader_max_block_bytes;
315317 size_t rows = 0 ;
318+ size_t block_bytes = 0 ;
316319
317320 bool success = false ;
318321 bool is_remove_bom = false ;
319322 if (_push_down_agg_type == TPushAggOp::type::COUNT) {
320- while (rows < batch_size && !_line_reader_eof) {
323+ while (rows < batch_size && !_line_reader_eof &&
324+ (max_block_bytes <= 0 || (int64_t )block_bytes < max_block_bytes)) {
321325 const uint8_t * ptr = nullptr ;
322326 size_t size = 0 ;
323327 RETURN_IF_ERROR (_line_reader->read_line (&ptr, &size, &_line_reader_eof, _io_ctx));
@@ -345,6 +349,7 @@ Status CsvReader::get_next_block(Block* block, size_t* read_rows, bool* eof) {
345349
346350 RETURN_IF_ERROR (_validate_line (Slice (ptr, size), &success));
347351 ++rows;
352+ block_bytes += size;
348353 }
349354 auto mutate_columns = block->mutate_columns ();
350355 for (auto & col : mutate_columns) {
@@ -353,7 +358,8 @@ Status CsvReader::get_next_block(Block* block, size_t* read_rows, bool* eof) {
353358 block->set_columns (std::move (mutate_columns));
354359 } else {
355360 auto columns = block->mutate_columns ();
356- while (rows < batch_size && !_line_reader_eof) {
361+ while (rows < batch_size && !_line_reader_eof &&
362+ (max_block_bytes <= 0 || (int64_t )block_bytes < max_block_bytes)) {
357363 const uint8_t * ptr = nullptr ;
358364 size_t size = 0 ;
359365 RETURN_IF_ERROR (_line_reader->read_line (&ptr, &size, &_line_reader_eof, _io_ctx));
@@ -384,6 +390,7 @@ Status CsvReader::get_next_block(Block* block, size_t* read_rows, bool* eof) {
384390 continue ;
385391 }
386392 RETURN_IF_ERROR (_fill_dest_columns (Slice (ptr, size), block, columns, &rows));
393+ block_bytes += size;
387394 }
388395 block->set_columns (std::move (columns));
389396 }
0 commit comments