viirya commented on code in PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#discussion_r1188848642
##########
arrow-cast/src/cast.rs:
##########
@@ -149,114 +153,54 @@ pub fn can_cast_types(from_type: &DataType, to_type:
&DataType) -> bool {
(Null | Int8 | Int16 | Int32 | Int64 | Float32 | Float64,
Decimal128(_, _)) |
(Null | Int8 | Int16 | Int32 | Int64 | Float32 | Float64,
Decimal256(_, _)) |
// decimal to unsigned numeric
- (Decimal128(_, _), UInt8 | UInt16 | UInt32 | UInt64) |
- (Decimal256(_, _), UInt8 | UInt16 | UInt32 | UInt64) |
+ (Decimal128(_, _)|Decimal256(_, _), UInt8 | UInt16 | UInt32 | UInt64) |
// decimal to signed numeric
- (Decimal128(_, _), Null | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64) |
- (Decimal256(_, _), Null | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64) => true,
+ (Decimal128(_, _)|Decimal256(_, _), Null | Int8 | Int16 | Int32 |
Int64 | Float32 | Float64) => true,
// decimal to Utf8
- (Decimal128(_, _), Utf8 | LargeUtf8) => true,
- (Decimal256(_, _), Utf8 | LargeUtf8) => true,
+ (Decimal128(_, _)|Decimal256(_, _), Utf8 | LargeUtf8) => true,
// Utf8 to decimal
- (Utf8 | LargeUtf8, Decimal128(_, _)) => true,
- (Utf8 | LargeUtf8, Decimal256(_, _)) => true,
- (Decimal128(_, _), _) => false,
- (_, Decimal128(_, _)) => false,
- (Decimal256(_, _), _) => false,
- (_, Decimal256(_, _)) => false,
+ (Utf8 | LargeUtf8, Decimal128(_, _)|Decimal256(_, _)) => true,
+ (Decimal128(_, _)|Decimal256(_, _), _) => false,
+ (_, Decimal128(_, _)|Decimal256(_, _)) => false,
(Struct(_), _) => false,
(_, Struct(_)) => false,
- (_, Boolean) => DataType::is_numeric(from_type) || from_type == &Utf8
|| from_type == &LargeUtf8,
- (Boolean, _) => DataType::is_numeric(to_type) || to_type == &Utf8 ||
to_type == &LargeUtf8,
+ (_, Boolean) => {
+ DataType::is_numeric(from_type)
+ || from_type == &Utf8
+ || from_type == &LargeUtf8
+ }
+ (Boolean, _) => {
+ DataType::is_numeric(to_type) || to_type == &Utf8 || to_type ==
&LargeUtf8
+ }
(Binary, LargeBinary | Utf8 | LargeUtf8 | FixedSizeBinary(_)) => true,
(LargeBinary, Binary | Utf8 | LargeUtf8 | FixedSizeBinary(_)) => true,
(FixedSizeBinary(_), Binary | LargeBinary) => true,
- (Utf8,
- Binary
- | LargeBinary
- | LargeUtf8
- | Date32
- | Date64
- | Time32(TimeUnit::Second)
- | Time32(TimeUnit::Millisecond)
- | Time64(TimeUnit::Microsecond)
- | Time64(TimeUnit::Nanosecond)
- | Timestamp(TimeUnit::Second, _)
- | Timestamp(TimeUnit::Millisecond, _)
- | Timestamp(TimeUnit::Microsecond, _)
- | Timestamp(TimeUnit::Nanosecond, _)
- | Interval(_)
- ) => true,
- (Utf8, _) => to_type.is_numeric() && to_type != &Float16,
- (LargeUtf8,
+ (
+ Utf8 | LargeUtf8,
Binary
| LargeBinary
| Utf8
+ | LargeUtf8
| Date32
| Date64
- | Time32(TimeUnit::Second)
- | Time32(TimeUnit::Millisecond)
- | Time64(TimeUnit::Microsecond)
- | Time64(TimeUnit::Nanosecond)
- | Timestamp(TimeUnit::Second, _)
- | Timestamp(TimeUnit::Millisecond, _)
- | Timestamp(TimeUnit::Microsecond, _)
- | Timestamp(TimeUnit::Nanosecond, _)
- | Interval(_)
+ | Time32(Second)
+ | Time32(Millisecond)
+ | Time64(Microsecond)
+ | Time64(Nanosecond)
+ | Timestamp(Second, _)
+ | Timestamp(Millisecond, _)
+ | Timestamp(Microsecond, _)
+ | Timestamp(Nanosecond, _)
+ | Interval(_),
) => true,
- (LargeUtf8, _) => to_type.is_numeric() && to_type != &Float16,
+ (Utf8 | LargeUtf8, _) => to_type.is_numeric() && to_type != &Float16,
(_, Utf8 | LargeUtf8) => from_type.is_primitive(),
// start numeric casts
(
- UInt8,
- UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- UInt16,
- UInt8 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64,
- ) => true,
-
- (
- UInt32,
- UInt8 | UInt16 | UInt64 | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64,
- ) => true,
-
- (
- UInt64,
- UInt8 | UInt16 | UInt32 | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64,
- ) => true,
-
- (
- Int8,
- UInt8 | UInt16 | UInt32 | UInt64 | Int16 | Int32 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- Int16,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int32 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- Int32,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- Int64,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Float32
| Float64,
- ) => true,
-
- (
- Float32,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 |
Float64,
- ) => true,
-
- (
- Float64,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 |
Float32,
+ UInt8|UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 |
Float32 | Float64,
Review Comment:
```suggestion
UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64
| Float32 | Float64,
```
##########
arrow-cast/src/cast.rs:
##########
@@ -149,114 +153,54 @@ pub fn can_cast_types(from_type: &DataType, to_type:
&DataType) -> bool {
(Null | Int8 | Int16 | Int32 | Int64 | Float32 | Float64,
Decimal128(_, _)) |
(Null | Int8 | Int16 | Int32 | Int64 | Float32 | Float64,
Decimal256(_, _)) |
// decimal to unsigned numeric
- (Decimal128(_, _), UInt8 | UInt16 | UInt32 | UInt64) |
- (Decimal256(_, _), UInt8 | UInt16 | UInt32 | UInt64) |
+ (Decimal128(_, _)|Decimal256(_, _), UInt8 | UInt16 | UInt32 | UInt64) |
// decimal to signed numeric
- (Decimal128(_, _), Null | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64) |
- (Decimal256(_, _), Null | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64) => true,
+ (Decimal128(_, _)|Decimal256(_, _), Null | Int8 | Int16 | Int32 |
Int64 | Float32 | Float64) => true,
// decimal to Utf8
- (Decimal128(_, _), Utf8 | LargeUtf8) => true,
- (Decimal256(_, _), Utf8 | LargeUtf8) => true,
+ (Decimal128(_, _)|Decimal256(_, _), Utf8 | LargeUtf8) => true,
// Utf8 to decimal
- (Utf8 | LargeUtf8, Decimal128(_, _)) => true,
- (Utf8 | LargeUtf8, Decimal256(_, _)) => true,
- (Decimal128(_, _), _) => false,
- (_, Decimal128(_, _)) => false,
- (Decimal256(_, _), _) => false,
- (_, Decimal256(_, _)) => false,
+ (Utf8 | LargeUtf8, Decimal128(_, _)|Decimal256(_, _)) => true,
+ (Decimal128(_, _)|Decimal256(_, _), _) => false,
+ (_, Decimal128(_, _)|Decimal256(_, _)) => false,
(Struct(_), _) => false,
(_, Struct(_)) => false,
- (_, Boolean) => DataType::is_numeric(from_type) || from_type == &Utf8
|| from_type == &LargeUtf8,
- (Boolean, _) => DataType::is_numeric(to_type) || to_type == &Utf8 ||
to_type == &LargeUtf8,
+ (_, Boolean) => {
+ DataType::is_numeric(from_type)
+ || from_type == &Utf8
+ || from_type == &LargeUtf8
+ }
+ (Boolean, _) => {
+ DataType::is_numeric(to_type) || to_type == &Utf8 || to_type ==
&LargeUtf8
+ }
(Binary, LargeBinary | Utf8 | LargeUtf8 | FixedSizeBinary(_)) => true,
(LargeBinary, Binary | Utf8 | LargeUtf8 | FixedSizeBinary(_)) => true,
(FixedSizeBinary(_), Binary | LargeBinary) => true,
- (Utf8,
- Binary
- | LargeBinary
- | LargeUtf8
- | Date32
- | Date64
- | Time32(TimeUnit::Second)
- | Time32(TimeUnit::Millisecond)
- | Time64(TimeUnit::Microsecond)
- | Time64(TimeUnit::Nanosecond)
- | Timestamp(TimeUnit::Second, _)
- | Timestamp(TimeUnit::Millisecond, _)
- | Timestamp(TimeUnit::Microsecond, _)
- | Timestamp(TimeUnit::Nanosecond, _)
- | Interval(_)
- ) => true,
- (Utf8, _) => to_type.is_numeric() && to_type != &Float16,
- (LargeUtf8,
+ (
+ Utf8 | LargeUtf8,
Binary
| LargeBinary
| Utf8
+ | LargeUtf8
| Date32
| Date64
- | Time32(TimeUnit::Second)
- | Time32(TimeUnit::Millisecond)
- | Time64(TimeUnit::Microsecond)
- | Time64(TimeUnit::Nanosecond)
- | Timestamp(TimeUnit::Second, _)
- | Timestamp(TimeUnit::Millisecond, _)
- | Timestamp(TimeUnit::Microsecond, _)
- | Timestamp(TimeUnit::Nanosecond, _)
- | Interval(_)
+ | Time32(Second)
+ | Time32(Millisecond)
+ | Time64(Microsecond)
+ | Time64(Nanosecond)
+ | Timestamp(Second, _)
+ | Timestamp(Millisecond, _)
+ | Timestamp(Microsecond, _)
+ | Timestamp(Nanosecond, _)
+ | Interval(_),
) => true,
- (LargeUtf8, _) => to_type.is_numeric() && to_type != &Float16,
+ (Utf8 | LargeUtf8, _) => to_type.is_numeric() && to_type != &Float16,
(_, Utf8 | LargeUtf8) => from_type.is_primitive(),
// start numeric casts
(
- UInt8,
- UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- UInt16,
- UInt8 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64,
- ) => true,
-
- (
- UInt32,
- UInt8 | UInt16 | UInt64 | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64,
- ) => true,
-
- (
- UInt64,
- UInt8 | UInt16 | UInt32 | Int8 | Int16 | Int32 | Int64 | Float32 |
Float64,
- ) => true,
-
- (
- Int8,
- UInt8 | UInt16 | UInt32 | UInt64 | Int16 | Int32 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- Int16,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int32 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- Int32,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int64 | Float32
| Float64,
- ) => true,
-
- (
- Int64,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Float32
| Float64,
- ) => true,
-
- (
- Float32,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 |
Float64,
- ) => true,
-
- (
- Float64,
- UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 |
Float32,
+ UInt8|UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 |
Float32 | Float64,
+ UInt8|UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64 |
Float32 | Float64,
Review Comment:
```suggestion
UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 | Int32 | Int64
| Float32 | Float64,
```
--
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]