Skip to content

Commit 21d6f81

Browse files
committed
Revert "fix(duckdb): use actual DuckDB schema for read provider (#650)"
This reverts commit 040aa83.
1 parent 9f0b9d1 commit 21d6f81

1 file changed

Lines changed: 11 additions & 75 deletions

File tree

core/src/duckdb.rs

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

487487
let pool = Arc::new(pool);
488-
make_initial_table(Arc::new(table_definition), &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);
489497

490498
let dyn_pool: Arc<DynDuckDbConnectionPool> = Arc::new(read_pool);
491499

@@ -502,28 +510,9 @@ impl TableProviderFactory for DuckDBTableProviderFactory {
502510
self.settings_registry
503511
.apply_settings(conn, &options, DuckDBSettingScope::Global)?;
504512

505-
// Read actual DuckDB schema after table creation (may differ from cmd.schema).
506-
let schema_conn = dyn_pool.connect().await?;
507-
let schema = get_schema(schema_conn, &TableReference::bare(name.clone()))
508-
.await
509-
.map_err(|e| DataFusionError::External(Box::new(e)))?;
510-
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-
524513
let read_provider = Arc::new(DuckDBTable::new_with_schema(
525514
&dyn_pool,
526-
schema,
515+
Arc::clone(&schema),
527516
TableReference::bare(name.clone()),
528517
None,
529518
Some(self.dialect.clone()),
@@ -809,7 +798,7 @@ pub(crate) mod tests {
809798
use crate::duckdb::write::DuckDBTableWriter;
810799

811800
use super::*;
812-
use arrow::datatypes::{DataType, Field, Schema, TimeUnit};
801+
use arrow::datatypes::{DataType, Field, Schema};
813802
use datafusion::common::{Constraints, ToDFSchema};
814803
use datafusion::logical_expr::CreateExternalTable;
815804
use datafusion::prelude::SessionContext;
@@ -1128,57 +1117,4 @@ pub(crate) mod tests {
11281117
assert_eq!(e.to_string(), "External error: Query execution failed.\nInvalid Input Error: Failed to cast value: Could not convert string 'invalid' to BOOL\nFor details, refer to the DuckDB manual: https://duckdb.org/docs/");
11291118
}
11301119
}
1131-
1132-
/// Verifies the read provider advertises actual DuckDB storage types,
1133-
/// not the requested cmd.schema types.
1134-
#[tokio::test]
1135-
async fn test_read_provider_schema_reflects_actual_duckdb_types() {
1136-
let table_name = TableReference::bare("test_timestamp_schema");
1137-
let schema = Schema::new(vec![
1138-
Field::new("id", DataType::Int32, false),
1139-
Field::new(
1140-
"created_at",
1141-
DataType::Timestamp(TimeUnit::Nanosecond, Some("UTC".into())),
1142-
false,
1143-
),
1144-
]);
1145-
1146-
let mut options = HashMap::new();
1147-
options.insert("mode".to_string(), "memory".to_string());
1148-
1149-
let factory = DuckDBTableProviderFactory::new(duckdb::AccessMode::ReadWrite);
1150-
let ctx = SessionContext::new();
1151-
let cmd = CreateExternalTable {
1152-
schema: Arc::new(schema.to_dfschema().expect("to df schema")),
1153-
name: table_name,
1154-
location: "".to_string(),
1155-
file_type: "".to_string(),
1156-
table_partition_cols: vec![],
1157-
if_not_exists: false,
1158-
definition: None,
1159-
order_exprs: vec![],
1160-
unbounded: false,
1161-
options,
1162-
constraints: Constraints::default(),
1163-
column_defaults: HashMap::new(),
1164-
temporary: false,
1165-
or_replace: false,
1166-
};
1167-
1168-
let table_provider = factory
1169-
.create(&ctx.state(), &cmd)
1170-
.await
1171-
.expect("table provider created");
1172-
1173-
let read_schema = table_provider.schema();
1174-
let ts_field = read_schema
1175-
.field_with_name("created_at")
1176-
.expect("created_at field exists");
1177-
1178-
// DuckDB stores TIMESTAMPTZ as Microsecond regardless of requested precision.
1179-
match ts_field.data_type() {
1180-
DataType::Timestamp(TimeUnit::Microsecond, _) => {}
1181-
other => panic!("Expected Timestamp(Microsecond, _), got {other:?}"),
1182-
}
1183-
}
11841120
}

0 commit comments

Comments
 (0)