File tree 3 files changed +17
-2
lines changed
3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
- // Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.
1
+ // Copyright 2022-2023 CeresDB Project Authors. Licensed under Apache-2.0.
2
2
3
3
//! Record batch
4
4
@@ -234,23 +234,33 @@ impl RecordBatch {
234
234
& self . schema
235
235
}
236
236
237
+ #[ inline]
238
+ pub fn is_empty ( & self ) -> bool {
239
+ self . num_rows ( ) == 0
240
+ }
241
+
237
242
// REQUIRE: index is valid
243
+ #[ inline]
238
244
pub fn column ( & self , index : usize ) -> & ColumnBlock {
239
245
& self . data . column_blocks [ index]
240
246
}
241
247
248
+ #[ inline]
242
249
pub fn num_columns ( & self ) -> usize {
243
250
self . schema . num_columns ( )
244
251
}
245
252
253
+ #[ inline]
246
254
pub fn num_rows ( & self ) -> usize {
247
255
self . data . num_rows ( )
248
256
}
249
257
258
+ #[ inline]
250
259
pub fn as_arrow_record_batch ( & self ) -> & ArrowRecordBatch {
251
260
& self . data . arrow_record_batch
252
261
}
253
262
263
+ #[ inline]
254
264
pub fn into_arrow_record_batch ( self ) -> ArrowRecordBatch {
255
265
self . data . arrow_record_batch
256
266
}
Original file line number Diff line number Diff line change 1
- // Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.
1
+ // Copyright 2022-2023 CeresDB Project Authors. Licensed under Apache-2.0.
2
2
3
3
//! Utilities for `RecordBatch` serialization using Arrow IPC
4
4
@@ -109,6 +109,7 @@ impl RecordBatchesEncoder {
109
109
let stream_writer = if let Some ( v) = & mut self . stream_writer {
110
110
v
111
111
} else {
112
+ // TODO: pre-allocate the buffer.
112
113
let buffer: Vec < u8 > = Vec :: new ( ) ;
113
114
let stream_writer =
114
115
StreamWriter :: try_new ( buffer, & batch. schema ( ) ) . context ( ArrowError ) ?;
Original file line number Diff line number Diff line change @@ -453,6 +453,10 @@ impl QueryResponseWriter {
453
453
}
454
454
455
455
pub fn write ( & mut self , batch : & RecordBatch ) -> Result < ( ) > {
456
+ if batch. is_empty ( ) {
457
+ return Ok ( ( ) ) ;
458
+ }
459
+
456
460
self . encoder
457
461
. write ( batch. as_arrow_record_batch ( ) )
458
462
. box_err ( )
You can’t perform that action at this time.
0 commit comments