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
Is your feature request related to a problem or challenge?
datafusion/datafusion/expr-common/src/signature.rs
Lines 1102 to 1119 in f27e50c
Example usages:
datafusion/datafusion/functions/src/unicode/reverse.rs
Lines 65 to 69 in f27e50c
datafusion/datafusion/functions-aggregate/src/approx_percentile_cont.rs
Lines 142 to 146 in f27e50c
When
desired_typeis aTypeSignatureClass::Native(_), its confusing to need to specifydefault_casted_typeto be the same; we already know our desired native type.Describe the solution you'd like
Perhaps a new API like
Then we could use it like
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