You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jackwener (via GitHub)" <gi...@apache.org> on 2023/05/09 14:36:15 UTC

[GitHub] [arrow-rs] jackwener opened a new pull request, #4185: refactor: simplify can_cast_types code.

jackwener opened a new pull request, #4185:
URL: https://github.com/apache/arrow-rs/pull/4185

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   simplify can_cast_types code
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] jackwener commented on pull request #4185: refactor: simplify can_cast_types code.

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#issuecomment-1540294828

   I don't know why don't exist `Time32(Microsecond)` `Time32(Nanosecond)`   `Time64(Second)`  `Time64(Millisecond)` in it.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4185: refactor: simplify can_cast_types code.

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#discussion_r1188847888


##########
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,

Review Comment:
   ```suggestion
           (Decimal128(_, _) | Decimal256(_, _), Utf8 | LargeUtf8) => true,
   ```



##########
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,

Review Comment:
   ```suggestion
           (Decimal128(_, _) | Decimal256(_, _), _) => false,
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] jackwener commented on a diff in pull request #4185: refactor: simplify can_cast_types code.

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on code in PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#discussion_r1189412019


##########
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,

Review Comment:
   > Hm, is this same as before?
   
   @viirya  Yes, I just merge them together



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4185: refactor: simplify can_cast_types code.

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#discussion_r1188848206


##########
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,

Review Comment:
   ```suggestion
           (Utf8 | LargeUtf8, Decimal128(_, _) | Decimal256(_, _)) => true,
   ```



##########
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,

Review Comment:
   ```suggestion
           (_, Decimal128(_, _) | Decimal256(_, _)) => false,
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4185: refactor: simplify can_cast_types code.

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#discussion_r1189397136


##########
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,

Review Comment:
   Hm, is this same as before?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] jackwener commented on pull request #4185: refactor: simplify can_cast_types code.

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#issuecomment-1541546002

   thanks @viirya 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4185: refactor: simplify can_cast_types code.

Posted by "viirya (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4185: refactor: simplify can_cast_types code.

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#discussion_r1188847554


##########
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) |

Review Comment:
   ```suggestion
           (Decimal128(_, _) | Decimal256(_, _), UInt8 | UInt16 | UInt32 | UInt64) |
   ```



##########
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,

Review Comment:
   ```suggestion
           (Decimal128(_, _) | Decimal256(_, _), Null | Int8 | Int16 | Int32 | Int64 | Float32 | Float64) => true,
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4185: refactor: simplify can_cast_types code.

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185#discussion_r1189420626


##########
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,

Review Comment:
   Okay.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #4185: refactor: simplify can_cast_types code.

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4185:
URL: https://github.com/apache/arrow-rs/pull/4185


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org