@@ -23,6 +23,7 @@ use databend_common_catalog::table_context::TableContext;
23
23
use databend_common_exception:: ErrorCode ;
24
24
use databend_common_exception:: Result ;
25
25
use databend_common_expression:: DataBlock ;
26
+ use databend_common_io:: constants:: DEFAULT_BLOCK_ROW_COUNT ;
26
27
use databend_common_pipeline_core:: processors:: Event ;
27
28
use databend_common_pipeline_core:: processors:: InputPort ;
28
29
use databend_common_pipeline_core:: processors:: OutputPort ;
@@ -37,6 +38,7 @@ use crate::io::BlockWriter;
37
38
use crate :: io:: StreamBlockBuilder ;
38
39
use crate :: io:: StreamBlockProperties ;
39
40
use crate :: FuseTable ;
41
+ use crate :: FUSE_OPT_KEY_ROW_PER_BLOCK ;
40
42
41
43
#[ allow( clippy:: large_enum_variant) ]
42
44
enum State {
@@ -72,7 +74,10 @@ impl TransformBlockWriter {
72
74
table_meta_timestamps : TableMetaTimestamps ,
73
75
with_tid : bool ,
74
76
) -> Result < ProcessorPtr > {
75
- let max_block_size = ctx. get_settings ( ) . get_max_block_size ( ) ? as usize ;
77
+ let max_block_size = std:: cmp:: min (
78
+ ctx. get_settings ( ) . get_max_block_size ( ) ? as usize ,
79
+ table. get_option ( FUSE_OPT_KEY_ROW_PER_BLOCK , DEFAULT_BLOCK_ROW_COUNT ) ,
80
+ ) ;
76
81
let properties = StreamBlockProperties :: try_create ( ctx, table, table_meta_timestamps) ?;
77
82
Ok ( ProcessorPtr :: create ( Box :: new ( TransformBlockWriter {
78
83
state : State :: Consume ,
@@ -157,22 +162,16 @@ impl Processor for TransformBlockWriter {
157
162
fn process ( & mut self ) -> Result < ( ) > {
158
163
match std:: mem:: replace ( & mut self . state , State :: Consume ) {
159
164
State :: Serialize ( block) => {
160
- let min_compressed = self . properties . write_settings . min_compressed_per_block ;
161
- let max_uncompressed = self . properties . write_settings . max_uncompressed_per_block ;
162
- let max_block_size = self . max_block_size ;
163
-
164
165
// Check if the datablock is valid, this is needed to ensure data is correct
165
166
block. check_valid ( ) ?;
166
- let builder = self . get_or_create_builder ( ) ?;
167
- let blocks = block. split_by_rows_no_tail ( max_block_size) ;
167
+ let blocks = block. split_by_rows_no_tail ( self . max_block_size ) ;
168
168
let mut blocks = VecDeque :: from ( blocks) ;
169
+
170
+ let builder = self . get_or_create_builder ( ) ?;
169
171
while let Some ( b) = blocks. pop_front ( ) {
170
172
builder. write ( b) ?;
171
173
172
- let file_size = builder. file_size ( ) ;
173
- let written_block_size = builder. block_size ( ) ;
174
-
175
- if file_size >= min_compressed || written_block_size >= max_uncompressed {
174
+ if builder. need_flush ( ) {
176
175
self . state = State :: Flush ;
177
176
178
177
for left in blocks {
@@ -184,7 +183,7 @@ impl Processor for TransformBlockWriter {
184
183
}
185
184
State :: Flush => {
186
185
let builder = self . builder . take ( ) . unwrap ( ) ;
187
- if builder. num_rows ( ) > 0 {
186
+ if ! builder. is_empty ( ) {
188
187
let serialized = builder. finish ( ) ?;
189
188
self . state = State :: Write ( serialized) ;
190
189
}
0 commit comments