@@ -22,7 +22,7 @@ use crate::planner::ExprPlanner;
2222use crate :: { AggregateUDF , ScalarUDF , UserDefinedLogicalNode , WindowUDF } ;
2323use arrow_schema:: Field ;
2424use datafusion_common:: types:: { LogicalTypeRef , NativeType } ;
25- use datafusion_common:: { HashMap , Result , not_impl_err , plan_datafusion_err } ;
25+ use datafusion_common:: { not_impl_err , plan_datafusion_err , HashMap , Result } ;
2626use std:: collections:: HashSet ;
2727use std:: fmt:: Debug ;
2828use std:: sync:: { Arc , RwLock } ;
@@ -272,6 +272,17 @@ pub trait ExtensionTypeRegistry: Debug + Send + Sync {
272272 extension_type : ExtensionTypeRegistrationRef ,
273273 ) -> Result < Option < ExtensionTypeRegistrationRef > > ;
274274
275+ /// Extends the registry with the provided extension types.
276+ ///
277+ /// Returns an error if the type cannot be registered, for example, if the registry is
278+ /// read-only.
279+ fn extend ( & self , extension_types : & [ ExtensionTypeRegistrationRef ] ) -> Result < ( ) > {
280+ for extension_type in extension_types {
281+ self . register_extension_type ( extension_type. clone ( ) ) ?;
282+ }
283+ Ok ( ( ) )
284+ }
285+
275286 /// Deregisters an extension type registration with the name `name`, returning the
276287 /// implementation that was deregistered.
277288 ///
@@ -283,6 +294,41 @@ pub trait ExtensionTypeRegistry: Debug + Send + Sync {
283294 ) -> Result < Option < ExtensionTypeRegistrationRef > > ;
284295}
285296
297+ /// A simple implementation of [ExtensionTypeRegistration] where the logical type instance can be
298+ /// obtained by cloning the inner [`LogicalTypeRef`].
299+ ///
300+ /// As a result, the logical type instance cannot depend on any parameters. For example, if the
301+ /// logical type is `Opaque(Uuid)`, and the `create_logical_type` method should return an instance
302+ /// of `Opaque` where `Uuid` is a parameter, then this implementation cannot be used, as the inner
303+ /// type (`Uuid`) needs to be extracted from the field and passed into the `Opaque` constructor.
304+ #[ derive( Debug ) ]
305+ pub struct SimpleExtensionTypeRegistration {
306+ /// The name of the extension type.
307+ name : String ,
308+ /// The logical type instance.
309+ logical_type : LogicalTypeRef ,
310+ }
311+
312+ impl SimpleExtensionTypeRegistration {
313+ /// Creates a new registration for the given `name` and `logical_type`.
314+ pub fn new_arc ( name : & str , logical_type : LogicalTypeRef ) -> Arc < Self > {
315+ Arc :: new ( Self {
316+ name : name. to_string ( ) ,
317+ logical_type,
318+ } )
319+ }
320+ }
321+
322+ impl ExtensionTypeRegistration for SimpleExtensionTypeRegistration {
323+ fn type_name ( & self ) -> & str {
324+ & self . name
325+ }
326+
327+ fn create_logical_type ( & self , _field : & Field ) -> Result < LogicalTypeRef > {
328+ Ok ( Arc :: clone ( & self . logical_type ) )
329+ }
330+ }
331+
286332/// An [`ExtensionTypeRegistry`] that uses in memory [`HashMap`]s.
287333#[ derive( Clone , Debug ) ]
288334pub struct MemoryExtensionTypeRegistry {
0 commit comments