1- use crate :: sql:: db_connection_pool:: {
2- self ,
3- dbconnection:: {
4- duckdbconn:: {
5- flatten_table_function_name, is_table_function, DuckDBParameter , DuckDbConnection ,
6- } ,
7- get_schema, DbConnection ,
8- } ,
9- duckdbpool:: DuckDbConnectionPool ,
10- DbConnectionPool , DbInstanceKey , Mode ,
11- } ;
121use crate :: sql:: sql_provider_datafusion;
132use crate :: util:: {
143 self ,
@@ -17,6 +6,20 @@ use crate::util::{
176 indexes:: IndexType ,
187 on_conflict:: { self , OnConflict } ,
198} ;
9+ use crate :: {
10+ sql:: db_connection_pool:: {
11+ self ,
12+ dbconnection:: {
13+ duckdbconn:: {
14+ flatten_table_function_name, is_table_function, DuckDBParameter , DuckDbConnection ,
15+ } ,
16+ get_schema, DbConnection ,
17+ } ,
18+ duckdbpool:: DuckDbConnectionPool ,
19+ DbConnectionPool , DbInstanceKey , Mode ,
20+ } ,
21+ InvalidTypeAction ,
22+ } ;
2023use arrow:: { array:: RecordBatch , datatypes:: SchemaRef } ;
2124use async_trait:: async_trait;
2225use datafusion:: {
@@ -120,6 +123,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
120123pub struct DuckDBTableProviderFactory {
121124 access_mode : AccessMode ,
122125 instances : Arc < Mutex < HashMap < DbInstanceKey , DuckDbConnectionPool > > > ,
126+ invalid_type_action : InvalidTypeAction ,
123127}
124128
125129const DUCKDB_DB_PATH_PARAM : & str = "open" ;
@@ -132,9 +136,16 @@ impl DuckDBTableProviderFactory {
132136 Self {
133137 access_mode,
134138 instances : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
139+ invalid_type_action : InvalidTypeAction :: Error ,
135140 }
136141 }
137142
143+ #[ must_use]
144+ pub fn with_invalid_type_action ( mut self , invalid_type_action : InvalidTypeAction ) -> Self {
145+ self . invalid_type_action = invalid_type_action;
146+ self
147+ }
148+
138149 #[ must_use]
139150 pub fn attach_databases ( & self , options : & HashMap < String , String > ) -> Vec < Arc < str > > {
140151 options
@@ -181,7 +192,9 @@ impl DuckDBTableProviderFactory {
181192 return Ok ( instance. clone ( ) ) ;
182193 }
183194
184- let pool = DuckDbConnectionPool :: new_memory ( ) . context ( DbConnectionPoolSnafu ) ?;
195+ let pool = DuckDbConnectionPool :: new_memory ( )
196+ . context ( DbConnectionPoolSnafu ) ?
197+ . with_invalid_type_action ( self . invalid_type_action . clone ( ) ) ;
185198
186199 instances. insert ( key, pool. clone ( ) ) ;
187200
@@ -201,7 +214,8 @@ impl DuckDBTableProviderFactory {
201214 }
202215
203216 let pool = DuckDbConnectionPool :: new_file ( & db_path, & self . access_mode )
204- . context ( DbConnectionPoolSnafu ) ?;
217+ . context ( DbConnectionPoolSnafu ) ?
218+ . with_invalid_type_action ( self . invalid_type_action . clone ( ) ) ;
205219
206220 instances. insert ( key, pool. clone ( ) ) ;
207221
0 commit comments