This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new b2f8e942c4 Minor: Improve zero partition check when inserting into
`MemTable` (#14024)
b2f8e942c4 is described below
commit b2f8e942c46f3cf6deb009a7d37e91422320b6b0
Author: Jonah Gao <[email protected]>
AuthorDate: Tue Jan 7 05:43:49 2025 +0800
Minor: Improve zero partition check when inserting into `MemTable` (#14024)
* Improve zero partition check when inserting into `MemTable`
* update err msg
---
datafusion/core/src/datasource/memory.rs | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/datafusion/core/src/datasource/memory.rs
b/datafusion/core/src/datasource/memory.rs
index e8cf216ee9..095dab9d91 100644
--- a/datafusion/core/src/datasource/memory.rs
+++ b/datafusion/core/src/datasource/memory.rs
@@ -265,10 +265,6 @@ impl TableProvider for MemTable {
input: Arc<dyn ExecutionPlan>,
insert_op: InsertOp,
) -> Result<Arc<dyn ExecutionPlan>> {
- if self.batches.is_empty() {
- return plan_err!("Cannot insert into MemTable with zero
partitions.");
- }
-
// If we are inserting into the table, any sort order may be messed up
so reset it here
*self.sort_order.lock() = vec![];
@@ -297,7 +293,7 @@ impl TableProvider for MemTable {
if insert_op != InsertOp::Append {
return not_impl_err!("{insert_op} not implemented for MemoryTable
yet");
}
- let sink = Arc::new(MemSink::new(self.batches.clone()));
+ let sink = Arc::new(MemSink::try_new(self.batches.clone())?);
Ok(Arc::new(DataSinkExec::new(
input,
sink,
@@ -340,9 +336,11 @@ impl MemSink {
/// Creates a new [`MemSink`].
///
/// The caller is responsible for ensuring that there is at least one
partition to insert into.
- fn new(batches: Vec<PartitionData>) -> Self {
- assert!(!batches.is_empty());
- Self { batches }
+ fn try_new(batches: Vec<PartitionData>) -> Result<Self> {
+ if batches.is_empty() {
+ return plan_err!("Cannot insert into MemTable with zero
partitions");
+ }
+ Ok(Self { batches })
}
}
@@ -805,7 +803,7 @@ mod tests {
.unwrap_err();
// Ensure that there is a descriptive error message
assert_eq!(
- "Error during planning: Cannot insert into MemTable with zero
partitions.",
+ "Error during planning: Cannot insert into MemTable with zero
partitions",
experiment_result.strip_backtrace()
);
Ok(())
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]