This is an automated email from the ASF dual-hosted git repository.
jiayuliu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 06f730e casting kernel can combine multi-match patterns (#883)
06f730e is described below
commit 06f730ee3668f17a231c2607886f169228f92964
Author: Jiayu Liu <[email protected]>
AuthorDate: Mon Nov 1 11:25:56 2021 +0800
casting kernel can combine multi-match patterns (#883)
---
arrow/src/compute/kernels/cast.rs | 178 ++++++++++++--------------------------
1 file changed, 57 insertions(+), 121 deletions(-)
diff --git a/arrow/src/compute/kernels/cast.rs
b/arrow/src/compute/kernels/cast.rs
index cd5d4a0..dbfa1a9 100644
--- a/arrow/src/compute/kernels/cast.rs
+++ b/arrow/src/compute/kernels/cast.rs
@@ -131,133 +131,71 @@ pub fn can_cast_types(from_type: &DataType, to_type:
&DataType) -> bool {
(Utf8, LargeUtf8) => true,
(LargeUtf8, Utf8) => true,
- (Utf8, Date32) => true,
- (Utf8, Date64) => true,
- (Utf8, Timestamp(TimeUnit::Nanosecond, None)) => true,
+ (Utf8, Date32 | Date64 | Timestamp(TimeUnit::Nanosecond, None)) =>
true,
(Utf8, _) => DataType::is_numeric(to_type),
- (LargeUtf8, Date32) => true,
- (LargeUtf8, Date64) => true,
- (LargeUtf8, Timestamp(TimeUnit::Nanosecond, None)) => true,
+ (LargeUtf8, Date32 | Date64 | Timestamp(TimeUnit::Nanosecond, None))
=> true,
(LargeUtf8, _) => DataType::is_numeric(to_type),
(Timestamp(_, _), Utf8) | (Timestamp(_, _), LargeUtf8) => true,
- (_, Utf8) | (_, LargeUtf8) => {
- DataType::is_numeric(from_type) || from_type == &Binary
- }
+ (_, Utf8 | LargeUtf8) => DataType::is_numeric(from_type) || from_type
== &Binary,
// start numeric casts
- (UInt8, UInt16) => true,
- (UInt8, UInt32) => true,
- (UInt8, UInt64) => true,
- (UInt8, Int8) => true,
- (UInt8, Int16) => true,
- (UInt8, Int32) => true,
- (UInt8, Int64) => true,
- (UInt8, Float32) => true,
- (UInt8, Float64) => true,
-
- (UInt16, UInt8) => true,
- (UInt16, UInt32) => true,
- (UInt16, UInt64) => true,
- (UInt16, Int8) => true,
- (UInt16, Int16) => true,
- (UInt16, Int32) => true,
- (UInt16, Int64) => true,
- (UInt16, Float32) => true,
- (UInt16, Float64) => true,
-
- (UInt32, UInt8) => true,
- (UInt32, UInt16) => true,
- (UInt32, UInt64) => true,
- (UInt32, Int8) => true,
- (UInt32, Int16) => true,
- (UInt32, Int32) => true,
- (UInt32, Int64) => true,
- (UInt32, Float32) => true,
- (UInt32, Float64) => true,
-
- (UInt64, UInt8) => true,
- (UInt64, UInt16) => true,
- (UInt64, UInt32) => true,
- (UInt64, Int8) => true,
- (UInt64, Int16) => true,
- (UInt64, Int32) => true,
- (UInt64, Int64) => true,
- (UInt64, Float32) => true,
- (UInt64, Float64) => true,
-
- (Int8, UInt8) => true,
- (Int8, UInt16) => true,
- (Int8, UInt32) => true,
- (Int8, UInt64) => true,
- (Int8, Int16) => true,
- (Int8, Int32) => true,
- (Int8, Int64) => true,
- (Int8, Float32) => true,
- (Int8, Float64) => true,
-
- (Int16, UInt8) => true,
- (Int16, UInt16) => true,
- (Int16, UInt32) => true,
- (Int16, UInt64) => true,
- (Int16, Int8) => true,
- (Int16, Int32) => true,
- (Int16, Int64) => true,
- (Int16, Float32) => true,
- (Int16, Float64) => true,
-
- (Int32, UInt8) => true,
- (Int32, UInt16) => true,
- (Int32, UInt32) => true,
- (Int32, UInt64) => true,
- (Int32, Int8) => true,
- (Int32, Int16) => true,
- (Int32, Int64) => true,
- (Int32, Float32) => true,
- (Int32, Float64) => true,
-
- (Int64, UInt8) => true,
- (Int64, UInt16) => true,
- (Int64, UInt32) => true,
- (Int64, UInt64) => true,
- (Int64, Int8) => true,
- (Int64, Int16) => true,
- (Int64, Int32) => true,
- (Int64, Float32) => true,
- (Int64, Float64) => true,
-
- (Float32, UInt8) => true,
- (Float32, UInt16) => true,
- (Float32, UInt32) => true,
- (Float32, UInt64) => true,
- (Float32, Int8) => true,
- (Float32, Int16) => true,
- (Float32, Int32) => true,
- (Float32, Int64) => true,
- (Float32, Float64) => true,
-
- (Float64, UInt8) => true,
- (Float64, UInt16) => true,
- (Float64, UInt32) => true,
- (Float64, UInt64) => true,
- (Float64, Int8) => true,
- (Float64, Int16) => true,
- (Float64, Int32) => true,
- (Float64, Int64) => true,
- (Float64, Float32) => true,
+ (
+ 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,
+ ) => true,
// end numeric casts
// temporal casts
- (Int32, Date32) => true,
- (Int32, Date64) => true,
- (Int32, Time32(_)) => true,
- (Date32, Int32) => true,
- (Date32, Int64) => true,
+ (Int32, Date32 | Date64 | Time32(_)) => true,
+ (Date32, Int32 | Int64) => true,
(Time32(_), Int32) => true,
- (Int64, Date64) => true,
- (Int64, Date32) => true,
- (Int64, Time64(_)) => true,
- (Date64, Int64) => true,
- (Date64, Int32) => true,
+ (Int64, Date64 | Date32 | Time64(_)) => true,
+ (Date64, Int64 | Int32) => true,
(Time64(_), Int64) => true,
(Date32, Date64) => true,
(Date64, Date32) => true,
@@ -271,9 +209,7 @@ pub fn can_cast_types(from_type: &DataType, to_type:
&DataType) -> bool {
}
(Timestamp(_, _), Int64) => true,
(Int64, Timestamp(_, _)) => true,
- (Timestamp(_, _), Timestamp(_, _)) => true,
- (Timestamp(_, _), Date32) => true,
- (Timestamp(_, _), Date64) => true,
+ (Timestamp(_, _), Timestamp(_, _) | Date32 | Date64) => true,
// date64 to timestamp might not make sense,
(Int64, Duration(_)) => true,
(_, _) => false,