Skip to content

Commit

Permalink
Signature::Coercible with user defined implicit casting (#14440)
Browse files Browse the repository at this point in the history
* coerciblev2

Signed-off-by: Jay Zhan <jayzhan211@gmail.com>

* repeat

Signed-off-by: Jay Zhan <jayzhan211@gmail.com>

* fix possible types

* replace all coerciblev1

* cleanup

* remove specialize logic

* comment

* err msg

* ci escape

* rm coerciblev1

Signed-off-by: Jay Zhan <jayzhan211@gmail.com>

* 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 <jayzhan211@gmail.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
  • Loading branch information
jayzhan211 and alamb authored Feb 17, 2025
1 parent b5d10c6 commit 71f9d0c
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 144 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions datafusion/catalog/src/information_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ fn get_udf_args_and_return_types(
udf: &Arc<ScalarUDF>,
) -> Result<Vec<(Vec<String>, Option<String>)>> {
let signature = udf.signature();
let arg_types = signature.type_signature.get_possible_types();
let arg_types = signature.type_signature.get_example_types();
if arg_types.is_empty() {
Ok(vec![(vec![], None)])
} else {
Expand All @@ -428,7 +428,7 @@ fn get_udaf_args_and_return_types(
udaf: &Arc<AggregateUDF>,
) -> Result<Vec<(Vec<String>, Option<String>)>> {
let signature = udaf.signature();
let arg_types = signature.type_signature.get_possible_types();
let arg_types = signature.type_signature.get_example_types();
if arg_types.is_empty() {
Ok(vec![(vec![], None)])
} else {
Expand All @@ -452,7 +452,7 @@ fn get_udwf_args_and_return_types(
udwf: &Arc<WindowUDF>,
) -> Result<Vec<(Vec<String>, Option<String>)>> {
let signature = udwf.signature();
let arg_types = signature.type_signature.get_possible_types();
let arg_types = signature.type_signature.get_example_types();
if arg_types.is_empty() {
Ok(vec![(vec![], None)])
} else {
Expand Down
9 changes: 9 additions & 0 deletions datafusion/common/src/types/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ impl LogicalType for NativeType {
TypeSignature::Native(self)
}

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

Expand Down Expand Up @@ -226,6 +231,10 @@ impl LogicalType for NativeType {
(Self::Decimal(p, s), _) if p <= &38 => Decimal128(*p, *s),
(Self::Decimal(p, s), _) => Decimal256(*p, *s),
(Self::Timestamp(tu, tz), _) => Timestamp(*tu, tz.clone()),
// If given type is Date, return the same type
(Self::Date, origin) if matches!(origin, Date32 | Date64) => {
origin.to_owned()
}
(Self::Date, _) => Date32,
(Self::Time(tu), _) => match tu {
TimeUnit::Second | TimeUnit::Millisecond => Time32(*tu),
Expand Down
1 change: 1 addition & 0 deletions datafusion/expr-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ path = "src/lib.rs"
[dependencies]
arrow = { workspace = true }
datafusion-common = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
paste = "^1.0"
Loading

0 comments on commit 71f9d0c

Please sign in to comment.