Skip to content

Commit fcd903d

Browse files
committed
ensure MemTable has at least one partition
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
1 parent 4dd7825 commit fcd903d

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

datafusion-examples/examples/sql_analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ from
274274
for table in tables {
275275
ctx.register_table(
276276
table.name,
277-
Arc::new(MemTable::try_new(Arc::new(table.schema.clone()), vec![])?),
277+
Arc::new(MemTable::try_new(Arc::new(table.schema.clone()), vec![vec![]])?),
278278
)?;
279279
}
280280
// We can create a LogicalPlan from a SQL query like this

datafusion/catalog/src/memory/table.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ pub struct MemTable {
6969
impl MemTable {
7070
/// Create a new in-memory table from the provided schema and record batches
7171
pub fn try_new(schema: SchemaRef, partitions: Vec<Vec<RecordBatch>>) -> Result<Self> {
72+
if partitions.is_empty() {
73+
return plan_err!("No partitions provided, expected at least one partition");
74+
}
75+
7276
for batches in partitions.iter().flatten() {
7377
let batches_schema = batches.schema();
7478
if !schema.contains(&batches_schema) {

datafusion/core/tests/dataframe/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4851,7 +4851,7 @@ async fn use_var_provider() -> Result<()> {
48514851
Field::new("bar", DataType::Int64, false),
48524852
]));
48534853

4854-
let mem_table = Arc::new(MemTable::try_new(schema, vec![])?);
4854+
let mem_table = Arc::new(MemTable::try_new(schema, vec![vec![]])?);
48554855

48564856
let config = SessionConfig::new()
48574857
.with_target_partitions(4)

docs/source/library-user-guide/building-logical-plans.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async fn main() -> Result<(), DataFusionError> {
181181
// TableProvider. For this example, we don't provide any data
182182
// but in production code, this would have `RecordBatch`es with
183183
// in memory data
184-
let table_provider = Arc::new(MemTable::try_new(Arc::new(schema), vec![])?);
184+
let table_provider = Arc::new(MemTable::try_new(Arc::new(schema), vec![vec![]])?);
185185
// Use the provider_as_source function to convert the TableProvider to a table source
186186
let table_source = provider_as_source(table_provider);
187187

0 commit comments

Comments
 (0)