Skip to content

Apache DataFusion SQL Query Engine

support unint <-> decimal (#4634)

Kun Liu5727ef366d12
diff --git a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
index 687e15b965..5d02d085d1 100644
--- a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
+++ b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
@@ -299,25 +299,6 @@ fn is_support_data_type(data_type: &DataType) -> bool {
)
}
-fn is_decimal_type(dt: &DataType) -> bool {
- matches!(dt, DataType::Decimal128(_, _))
-}
-
-fn is_unsigned_type(dt: &DataType) -> bool {
- matches!(
- dt,
- DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | DataType::UInt64
- )
-}
-
-/// Until https://github.com/apache/arrow-rs/issues/1043 is done
-/// (support for unsigned <--> decimal casts) we also don't do that
-/// kind of cast in this optimizer
-fn is_unsupported_cast(dt1: &DataType, dt2: &DataType) -> bool {
- (is_decimal_type(dt1) && is_unsigned_type(dt2))
- || (is_decimal_type(dt2) && is_unsigned_type(dt1))
-}
-
fn try_cast_literal_to_type(
lit_value: &ScalarValue,
target_type: &DataType,
@@ -327,9 +308,6 @@ fn try_cast_literal_to_type(
if !is_support_data_type(&lit_data_type) || !is_support_data_type(target_type) {
return Ok(None);
}
- if is_unsupported_cast(&lit_data_type, target_type) {
- return Ok(None);
- }
if lit_value.is_null() {
// null value can be cast to any type of null value
return Ok(Some(ScalarValue::try_from(target_type)?));
@@ -800,12 +778,7 @@ mod tests {
for s1 in &scalars {
for s2 in &scalars {
- let expected_value =
- if is_unsupported_cast(&s1.get_datatype(), &s2.get_datatype()) {
- ExpectedCast::NoValue
- } else {
- ExpectedCast::Value(s2.clone())
- };
+ let expected_value = ExpectedCast::Value(s2.clone());
expect_cast(s1.clone(), s2.get_datatype(), expected_value);
}
@@ -830,12 +803,7 @@ mod tests {
for s1 in &scalars {
for s2 in &scalars {
- let expected_value =
- if is_unsupported_cast(&s1.get_datatype(), &s2.get_datatype()) {
- ExpectedCast::NoValue
- } else {
- ExpectedCast::Value(s2.clone())
- };
+ let expected_value = ExpectedCast::Value(s2.clone());
expect_cast(s1.clone(), s2.get_datatype(), expected_value);
}