Skip to content

Coercion::new_implicit is confusing when desired type is TypeSignatureClass::Native #24135

Description

@Jefffrey

Is your feature request related to a problem or challenge?

/// Create a new coercion with implicit coercion rules.
///
/// `allowed_source_types` defines the possible types that can be coerced to `desired_type`.
/// `default_casted_type` is the default type to be used for coercion if we cast from other types via `allowed_source_types`.
pub fn new_implicit(
desired_type: TypeSignatureClass,
allowed_source_types: Vec<TypeSignatureClass>,
default_casted_type: NativeType,
) -> Self {
Self::Implicit {
desired_type,
implicit_coercion: ImplicitCoercion {
allowed_source_types,
default_casted_type,
},
encoding_preservation: EncodingPreservation::default(),
}
}

Example usages:

Coercion::new_implicit(
TypeSignatureClass::Native(logical_string()),
vec![TypeSignatureClass::Any],
NativeType::String,
)

Coercion::new_implicit(
TypeSignatureClass::Native(logical_float64()),
vec![TypeSignatureClass::Numeric],
NativeType::Float64,
),

When desired_type is a TypeSignatureClass::Native(_), its confusing to need to specify default_casted_type to be the same; we already know our desired native type.

Describe the solution you'd like

Perhaps a new API like

pub fn new_implicit_native(
    desired_type: LogicalTypeRef,
    allowed_source_types: Vec<TypeSignatureClass>,
) -> Self {
    Self::new_implicit(
        TypeSignatureClass::Native(desired_type),
        allowed_source_types,
        desired_type.native().clone(),
    )
}

Then we could use it like

Coercion::new_implicit_native(
    logical_string(),
    vec![TypeSignatureClass::Any],
)

And see where we can use this hopefully more intuitive API

Describe alternatives you've considered

Is there a better/cleaner way to handle this? Open to suggestions

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions