Skip to content

Commit 31ca29f

Browse files
committed
Comments and use field in extension type registry
1 parent 3d23b9f commit 31ca29f

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

datafusion/expr/src/registry.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use crate::expr_rewriter::FunctionRewrite;
2121
use crate::planner::ExprPlanner;
2222
use crate::{AggregateUDF, ScalarUDF, UserDefinedLogicalNode, WindowUDF};
23-
use arrow::datatypes::DataType;
23+
use arrow_schema::Field;
2424
use datafusion_common::types::{LogicalTypeRef, NativeType};
2525
use datafusion_common::{not_impl_err, plan_datafusion_err, HashMap, Result};
2626
use std::collections::HashSet;
@@ -218,20 +218,27 @@ impl FunctionRegistry for MemoryFunctionRegistry {
218218
}
219219
}
220220

221-
/// TODO
221+
/// The registration of an extension type.
222+
///
223+
/// Implementations of this trait are responsible for *creating* instances of [LogicalType] that
224+
/// represent the semantics of an extension type. One cannot directly register the [LogicalType]
225+
/// instances because some extension types may have parameters that are unknown at compile time
226+
/// (e.g., the unknown type in [Opaque](arrow_schema::extension::Opaque)).
222227
pub trait ExtensionTypeRegistration: Debug {
223-
/// TODO
228+
/// The name of the extension type.
229+
///
230+
/// This name will be used to find the correct [ExtensionTypeRegistration] when an extension
231+
/// type is encountered.
224232
fn type_name(&self) -> &str;
225233

226-
/// TODO
227-
fn create_logical_type(
228-
&self,
229-
data_type: DataType,
230-
metadata: HashMap<String, String>,
231-
) -> Result<LogicalTypeRef>;
234+
/// Creates a logical type instance from the provided `field`.
235+
///
236+
/// The resulting [LogicalTypeRef] should only capture the *type information*, not any other
237+
/// metadata or nullability information that is part of the field.
238+
fn create_logical_type(&self, field: Field) -> Result<LogicalTypeRef>;
232239
}
233240

234-
/// TODO
241+
/// A cheaply clonable pointer to an [ExtensionTypeRegistration].
235242
type ExtensionTypeRegistrationRef = Arc<dyn ExtensionTypeRegistration>;
236243

237244
/// Supports registering custom [LogicalType]s, including native types.
@@ -242,16 +249,12 @@ pub trait ExtensionTypeRegistry {
242249
fn extension_type(&self, name: &str) -> Result<ExtensionTypeRegistrationRef>;
243250

244251
/// TODO
245-
fn create_logical_type_for(
246-
&self,
247-
data_type: DataType,
248-
metadata: HashMap<String, String>,
249-
) -> Result<LogicalTypeRef> {
250-
match metadata.get(arrow_schema::extension::EXTENSION_TYPE_NAME_KEY) {
251-
None => Ok(Arc::new(NativeType::from(data_type))),
252+
fn create_logical_type_for_field(&self, field: Field) -> Result<LogicalTypeRef> {
253+
match field.extension_type_name() {
254+
None => Ok(Arc::new(NativeType::from(field.data_type()))),
252255
Some(name) => {
253256
let extension_type = self.extension_type(name)?;
254-
extension_type.create_logical_type(data_type, metadata)
257+
extension_type.create_logical_type(field)
255258
}
256259
}
257260
}

0 commit comments

Comments
 (0)