@@ -265,10 +265,6 @@ impl TableProvider for MemTable {
265
265
input : Arc < dyn ExecutionPlan > ,
266
266
insert_op : InsertOp ,
267
267
) -> Result < Arc < dyn ExecutionPlan > > {
268
- if self . batches . is_empty ( ) {
269
- return plan_err ! ( "Cannot insert into MemTable with zero partitions." ) ;
270
- }
271
-
272
268
// If we are inserting into the table, any sort order may be messed up so reset it here
273
269
* self . sort_order . lock ( ) = vec ! [ ] ;
274
270
@@ -297,7 +293,7 @@ impl TableProvider for MemTable {
297
293
if insert_op != InsertOp :: Append {
298
294
return not_impl_err ! ( "{insert_op} not implemented for MemoryTable yet" ) ;
299
295
}
300
- let sink = Arc :: new ( MemSink :: new ( self . batches . clone ( ) ) ) ;
296
+ let sink = Arc :: new ( MemSink :: try_new ( self . batches . clone ( ) ) ? ) ;
301
297
Ok ( Arc :: new ( DataSinkExec :: new (
302
298
input,
303
299
sink,
@@ -340,9 +336,11 @@ impl MemSink {
340
336
/// Creates a new [`MemSink`].
341
337
///
342
338
/// The caller is responsible for ensuring that there is at least one partition to insert into.
343
- fn new ( batches : Vec < PartitionData > ) -> Self {
344
- assert ! ( !batches. is_empty( ) ) ;
345
- Self { batches }
339
+ fn try_new ( batches : Vec < PartitionData > ) -> Result < Self > {
340
+ if batches. is_empty ( ) {
341
+ return plan_err ! ( "Cannot insert into MemTable with zero partitions" ) ;
342
+ }
343
+ Ok ( Self { batches } )
346
344
}
347
345
}
348
346
@@ -805,7 +803,7 @@ mod tests {
805
803
. unwrap_err ( ) ;
806
804
// Ensure that there is a descriptive error message
807
805
assert_eq ! (
808
- "Error during planning: Cannot insert into MemTable with zero partitions. " ,
806
+ "Error during planning: Cannot insert into MemTable with zero partitions" ,
809
807
experiment_result. strip_backtrace( )
810
808
) ;
811
809
Ok ( ( ) )
0 commit comments