Skip to content

Commit 71f9d0c

Browse files
jayzhan211alamb
andauthoredFeb 17, 2025
Signature::Coercible with user defined implicit casting (apache#14440)
* coerciblev2 Signed-off-by: Jay Zhan <[email protected]> * repeat Signed-off-by: Jay Zhan <[email protected]> * fix possible types * replace all coerciblev1 * cleanup * remove specialize logic * comment * err msg * ci escape * rm coerciblev1 Signed-off-by: Jay Zhan <[email protected]> * fmt * rename * rename * refactor * make default_casted_type private * cleanup * fmt * integer * rm binary for ascii * rm unused * conflit * fmt * Rename get_example_types, make method on TypeSignatureClass * Move more logic into TypeSignatureClass * fix docs * 46 * enum * fmt * fmt * doc * upd doc --------- Signed-off-by: Jay Zhan <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
1 parent b5d10c6 commit 71f9d0c

File tree

10 files changed

+403
-144
lines changed

10 files changed

+403
-144
lines changed
 

‎Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎datafusion/catalog/src/information_schema.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ fn get_udf_args_and_return_types(
405405
udf: &Arc<ScalarUDF>,
406406
) -> Result<Vec<(Vec<String>, Option<String>)>> {
407407
let signature = udf.signature();
408-
let arg_types = signature.type_signature.get_possible_types();
408+
let arg_types = signature.type_signature.get_example_types();
409409
if arg_types.is_empty() {
410410
Ok(vec![(vec![], None)])
411411
} else {
@@ -428,7 +428,7 @@ fn get_udaf_args_and_return_types(
428428
udaf: &Arc<AggregateUDF>,
429429
) -> Result<Vec<(Vec<String>, Option<String>)>> {
430430
let signature = udaf.signature();
431-
let arg_types = signature.type_signature.get_possible_types();
431+
let arg_types = signature.type_signature.get_example_types();
432432
if arg_types.is_empty() {
433433
Ok(vec![(vec![], None)])
434434
} else {
@@ -452,7 +452,7 @@ fn get_udwf_args_and_return_types(
452452
udwf: &Arc<WindowUDF>,
453453
) -> Result<Vec<(Vec<String>, Option<String>)>> {
454454
let signature = udwf.signature();
455-
let arg_types = signature.type_signature.get_possible_types();
455+
let arg_types = signature.type_signature.get_example_types();
456456
if arg_types.is_empty() {
457457
Ok(vec![(vec![], None)])
458458
} else {

‎datafusion/common/src/types/native.rs

+9
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ impl LogicalType for NativeType {
198198
TypeSignature::Native(self)
199199
}
200200

201+
/// Returns the default casted type for the given arrow type
202+
///
203+
/// For types like String or Date, multiple arrow types mapped to the same logical type
204+
/// If the given arrow type is one of them, we return the same type
205+
/// Otherwise, we define the default casted type for the given arrow type
201206
fn default_cast_for(&self, origin: &DataType) -> Result<DataType> {
202207
use DataType::*;
203208

@@ -226,6 +231,10 @@ impl LogicalType for NativeType {
226231
(Self::Decimal(p, s), _) if p <= &38 => Decimal128(*p, *s),
227232
(Self::Decimal(p, s), _) => Decimal256(*p, *s),
228233
(Self::Timestamp(tu, tz), _) => Timestamp(*tu, tz.clone()),
234+
// If given type is Date, return the same type
235+
(Self::Date, origin) if matches!(origin, Date32 | Date64) => {
236+
origin.to_owned()
237+
}
229238
(Self::Date, _) => Date32,
230239
(Self::Time(tu), _) => match tu {
231240
TimeUnit::Second | TimeUnit::Millisecond => Time32(*tu),

‎datafusion/expr-common/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ path = "src/lib.rs"
3939
[dependencies]
4040
arrow = { workspace = true }
4141
datafusion-common = { workspace = true }
42+
indexmap = { workspace = true }
4243
itertools = { workspace = true }
4344
paste = "^1.0"

0 commit comments

Comments
 (0)