Skip to content

Commit 38c47b6

Browse files
committed
fix: use actual DuckDB schema for TableDefinition as well
Address review feedback: read the actual DuckDB schema into the schema variable used by both TableDefinition (write path) and the read provider, rather than only fixing the read provider.
1 parent 4ad04d8 commit 38c47b6

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

core/src/duckdb.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,7 @@ impl TableProviderFactory for DuckDBTableProviderFactory {
485485
.with_indexes(indexes.clone());
486486

487487
let pool = Arc::new(pool);
488-
make_initial_table(Arc::new(table_definition.clone()), &pool)?;
489-
490-
let write_settings = DuckDBWriteSettings::from_params(&options);
491-
492-
let table_writer_builder = DuckDBTableWriterBuilder::new()
493-
.with_table_definition(table_definition)
494-
.with_pool(pool)
495-
.set_on_conflict(on_conflict)
496-
.with_write_settings(write_settings);
488+
make_initial_table(Arc::new(table_definition), &pool)?;
497489

498490
let dyn_pool: Arc<DynDuckDbConnectionPool> = Arc::new(read_pool);
499491

@@ -510,15 +502,28 @@ impl TableProviderFactory for DuckDBTableProviderFactory {
510502
self.settings_registry
511503
.apply_settings(conn, &options, DuckDBSettingScope::Global)?;
512504

513-
// Use actual DuckDB storage schema for the read provider (may differ from cmd.schema).
505+
// Read actual DuckDB schema after table creation (may differ from cmd.schema).
514506
let schema_conn = dyn_pool.connect().await?;
515-
let read_schema = get_schema(schema_conn, &TableReference::bare(name.clone()))
507+
let schema = get_schema(schema_conn, &TableReference::bare(name.clone()))
516508
.await
517509
.map_err(|e| DataFusionError::External(Box::new(e)))?;
518510

511+
let table_definition =
512+
TableDefinition::new(RelationName::new(name.clone()), Arc::clone(&schema))
513+
.with_constraints(cmd.constraints.clone())
514+
.with_indexes(indexes.clone());
515+
516+
let write_settings = DuckDBWriteSettings::from_params(&options);
517+
518+
let table_writer_builder = DuckDBTableWriterBuilder::new()
519+
.with_table_definition(table_definition)
520+
.with_pool(pool)
521+
.set_on_conflict(on_conflict)
522+
.with_write_settings(write_settings);
523+
519524
let read_provider = Arc::new(DuckDBTable::new_with_schema(
520525
&dyn_pool,
521-
read_schema,
526+
schema,
522527
TableReference::bare(name.clone()),
523528
None,
524529
Some(self.dialect.clone()),

0 commit comments

Comments
 (0)