isidentical commented on code in PR #4147:
URL: https://github.com/apache/arrow-datafusion/pull/4147#discussion_r1017236065
##########
datafusion/optimizer/src/unwrap_cast_in_comparison.rs:
##########
@@ -653,4 +655,196 @@ mod tests {
fn null_decimal(precision: u8, scale: u8) -> Expr {
lit(ScalarValue::Decimal128(None, precision, scale))
}
+
+ #[test]
+ fn test_try_cast_to_type_nulls() {
+ // test values that can be cast to/from all integer types
+ let scalars = vec![
+ ScalarValue::Int8(None),
+ ScalarValue::Int16(None),
+ ScalarValue::Int32(None),
+ ScalarValue::Int64(None),
+ ScalarValue::Decimal128(None, 3, 0),
+ ScalarValue::Decimal128(None, 8, 2),
+ ];
+
+ for s1 in &scalars {
+ for s2 in &scalars {
+ expect_cast(
+ s1.clone(),
+ s2.get_datatype(),
+ ExpectedCast::Value(s2.clone()),
+ );
+ }
+ }
+ }
+
+ #[test]
+ fn test_try_cast_to_type_int_in_range() {
+ // test values that can be cast to/from all integer types
+ let scalars = vec![
+ ScalarValue::Int8(Some(123)),
+ ScalarValue::Int16(Some(123)),
+ ScalarValue::Int32(Some(123)),
+ ScalarValue::Int64(Some(123)),
+ ScalarValue::Decimal128(Some(123), 3, 0),
+ ScalarValue::Decimal128(Some(12300), 8, 2),
+ ];
+
+ for s1 in &scalars {
+ for s2 in &scalars {
+ expect_cast(
+ s1.clone(),
+ s2.get_datatype(),
+ ExpectedCast::Value(s2.clone()),
+ );
+ }
+ }
+ }
+
+ #[test]
+ fn test_try_cast_to_type_int_out_of_range() {
+ let max_i64 = ScalarValue::Int64(Some(i64::MAX));
Review Comment:
~~@alamb if I didn't miss any, I guess it makes sense to also include some
signed -> unsigned conversions here as well.~~ Seems like unsigned types are
not supported yet.
##########
datafusion/optimizer/src/unwrap_cast_in_comparison.rs:
##########
@@ -653,4 +655,196 @@ mod tests {
fn null_decimal(precision: u8, scale: u8) -> Expr {
lit(ScalarValue::Decimal128(None, precision, scale))
}
+
+ #[test]
+ fn test_try_cast_to_type_nulls() {
+ // test values that can be cast to/from all integer types
+ let scalars = vec![
+ ScalarValue::Int8(None),
+ ScalarValue::Int16(None),
+ ScalarValue::Int32(None),
+ ScalarValue::Int64(None),
+ ScalarValue::Decimal128(None, 3, 0),
+ ScalarValue::Decimal128(None, 8, 2),
+ ];
+
+ for s1 in &scalars {
+ for s2 in &scalars {
+ expect_cast(
+ s1.clone(),
+ s2.get_datatype(),
+ ExpectedCast::Value(s2.clone()),
+ );
+ }
+ }
+ }
+
+ #[test]
+ fn test_try_cast_to_type_int_in_range() {
+ // test values that can be cast to/from all integer types
+ let scalars = vec![
+ ScalarValue::Int8(Some(123)),
+ ScalarValue::Int16(Some(123)),
+ ScalarValue::Int32(Some(123)),
+ ScalarValue::Int64(Some(123)),
+ ScalarValue::Decimal128(Some(123), 3, 0),
+ ScalarValue::Decimal128(Some(12300), 8, 2),
+ ];
+
+ for s1 in &scalars {
+ for s2 in &scalars {
+ expect_cast(
+ s1.clone(),
+ s2.get_datatype(),
+ ExpectedCast::Value(s2.clone()),
+ );
+ }
+ }
+ }
+
+ #[test]
+ fn test_try_cast_to_type_int_out_of_range() {
+ let max_i64 = ScalarValue::Int64(Some(i64::MAX));
Review Comment:
~~@alamb if I didn't miss any, I guess it makes sense to also include some
signed -> unsigned conversions here as well.~~ Seems like unsigned types are
not supported yet. Can be ignored.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]