You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/22 12:37:39 UTC
[GitHub] [arrow-rs] liukun4515 opened a new pull request, #1922: support NULL type values to decimal
liukun4515 opened a new pull request, #1922:
URL: https://github.com/apache/arrow-rs/pull/1922
# 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 #1921
# 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?
<!---
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# 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] alamb commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r903726625
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -4312,6 +4314,24 @@ mod tests {
assert_eq!(array_to_strings(&cast_array), expected);
}
+ #[test]
+ fn test_cast_null_array_to_decimal_array() {
+ let data_type = DataType::Decimal(12, 4);
+ let array = new_null_array(&DataType::Null, 4);
+ assert_eq!(array.data_type(), &DataType::Null);
+ let cast_array = cast(&array, &data_type).expect("cast failed");
+ assert_eq!(cast_array.data_type(), &data_type);
+ for i in 0..4 {
+ assert!(cast_array.is_null(i));
+ }
+
+ // Now: can't convert decimal to NULL type
+ let array = new_null_array(&data_type, 4);
Review Comment:
Why not support casting `Decimal` to `Null`? If we don't add support in this PR can / should file a ticket to add it in a follow on I think
--
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] codecov-commenter commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1165221346
# [Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1922?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#1922](https://codecov.io/gh/apache/arrow-rs/pull/1922?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3a7344a) into [master](https://codecov.io/gh/apache/arrow-rs/commit/50a9dd5d7a697a894f2b8028190b8d1cb31a1096?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (50a9dd5) will **increase** coverage by `0.05%`.
> The diff coverage is `100.00%`.
```diff
@@ Coverage Diff @@
## master #1922 +/- ##
==========================================
+ Coverage 83.42% 83.47% +0.05%
==========================================
Files 214 221 +7
Lines 57004 57042 +38
==========================================
+ Hits 47553 47615 +62
+ Misses 9451 9427 -24
```
| [Impacted Files](https://codecov.io/gh/apache/arrow-rs/pull/1922?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [arrow/src/compute/kernels/cast.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2NvbXB1dGUva2VybmVscy9jYXN0LnJz) | `95.80% <100.00%> (+0.03%)` | :arrow_up: |
| [arrow/src/array/builder/buffer\_builder.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2FycmF5L2J1aWxkZXIvYnVmZmVyX2J1aWxkZXIucnM=) | `85.49% <0.00%> (-7.31%)` | :arrow_down: |
| [parquet/src/arrow/array\_reader/mod.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldC9zcmMvYXJyb3cvYXJyYXlfcmVhZGVyL21vZC5ycw==) | `88.23% <0.00%> (-2.54%)` | :arrow_down: |
| [arrow/src/datatypes/datatype.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2RhdGF0eXBlcy9kYXRhdHlwZS5ycw==) | `65.42% <0.00%> (-0.38%)` | :arrow_down: |
| [arrow/src/array/data.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2FycmF5L2RhdGEucnM=) | `84.16% <0.00%> (ø)` | |
| [parquet/src/arrow/arrow\_writer/mod.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldC9zcmMvYXJyb3cvYXJyb3dfd3JpdGVyL21vZC5ycw==) | `97.53% <0.00%> (ø)` | |
| [parquet/src/arrow/array\_reader/primitive\_array.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldC9zcmMvYXJyb3cvYXJyYXlfcmVhZGVyL3ByaW1pdGl2ZV9hcnJheS5ycw==) | `89.65% <0.00%> (ø)` | |
| [...uet/src/arrow/array\_reader/complex\_object\_array.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldC9zcmMvYXJyb3cvYXJyYXlfcmVhZGVyL2NvbXBsZXhfb2JqZWN0X2FycmF5LnJz) | `94.27% <0.00%> (ø)` | |
| [parquet/src/arrow/array\_reader/struct\_array.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldC9zcmMvYXJyb3cvYXJyYXlfcmVhZGVyL3N0cnVjdF9hcnJheS5ycw==) | `88.67% <0.00%> (ø)` | |
| [parquet/src/arrow/array\_reader/null\_array.rs](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldC9zcmMvYXJyb3cvYXJyYXlfcmVhZGVyL251bGxfYXJyYXkucnM=) | `88.00% <0.00%> (ø)` | |
| ... and [7 more](https://codecov.io/gh/apache/arrow-rs/pull/1922/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1922?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1922?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [50a9dd5...3a7344a](https://codecov.io/gh/apache/arrow-rs/pull/1922?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904473324
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
> > I think we can convert Null Data type to other data type, and can't convert other data type to Null Data type.
>
> Yes, this is how cast works in Spark and also in C++ Arrow repo.
We can left these comments and discuss with other reviewers.
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904472049
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
From this comment https://github.com/apache/arrow-datafusion/issues/2759#issuecomment-1163865423, I compare the decimal with Null data type or null value of boolean data type in the spark, we can get that in the spark the null of boolean data type is not compatible with decimal data type, and the null of Null data type is compatible with decimal data type.
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904454454
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
agree with you @viirya @alamb
I also noticed this problem when I implement casting the Null Type to decimal data type.
You can review this https://github.com/apache/arrow-rs/pull/884
My initial thought was that casting other data type to Null Type is not right.
--
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] liukun4515 commented on pull request #1922: support NULL type values to decimal
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1163046287
@viirya @alamb @tustvold PTAL
--
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 pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1165211892
Sounds good to merge this to 17.0.0.
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r905637663
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
> I agree with @nevi-me that a preferable way would be:
>
> 1. Not allow `type` -> `NULL` in the `cast` and `try_cast` kernels
> 2. Add some other function (or maybe just add an example on the `cast` documentation pointing at `new_null_array` as the way to "cast" any array to null)
>
> I would personally suggest:
>
> 1. Add support in this PR to cast Decimal --> Null to be consistent with other `cast` kernels
> 2. As a follow on PR (perhaps to close [Disallow cast from other datatypes to NullType #1923](https://github.com/apache/arrow-rs/issues/1923)) we can then remove the `type` -> `NULL` casts
agree with the proposal.
I think this pr can be merged if we follow above suggestion.
--
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 merged pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya merged PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922
--
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 #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904128383
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
Review Comment:
```suggestion
(Null | Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
```
--
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 #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904175802
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
I think currently Cast kernel is not correct on casting to NullType behavior. It is not following C++ implementation. I issued #https://github.com/apache/arrow-rs/issues/1923 to follow it. I may take some time to propose a fix.
--
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 #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904468878
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
> I think we can convert Null Data type to other data type, and can't convert other data type to Null Data type.
Yes, this is how cast works in Spark and also in C++ Arrow repo.
--
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] liukun4515 commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1165214732
> Sounds good to merge this to 17.0.0.
Thanks @viirya
If the ci pass, please help to merge 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] alamb commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1163082444
Looks like there is a test failure: https://github.com/apache/arrow-rs/runs/7004119046?check_suite_focus=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] liukun4515 commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1163116023
> Looks like there is a test failure: https://github.com/apache/arrow-rs/runs/7004119046?check_suite_focus=true
I will try to fix this case.
--
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 #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904163992
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
Hmm, is it allowable to cast Decimal type to Null type? It looks a bit weird to me. For example, I re-checked Spark and it doesn't allow this kind of casting (anytype to NullType).
I also checked C++ Cast kernels. Mostly the datatypes cannot cast to NullType (e.g. https://github.com/apache/arrow/blob/53752adc6b81166cd4ee7db5a819494042f29197/cpp/src/arrow/compute/kernels/scalar_cast_test.cc#L187-L211). I said "mostly" because I don't see explicit tests for other cases like Decimal, but I suspect that it is not allowed but just lack of test coverage.
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904460828
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
In the type system, if we want to compare two types, we should get the coerced or common data type and convert them to the same common data type.
I think the type of IN32 can't be compared with the type of Null, we should cast the Null type to the INT32 data type, but I think cast INT32 data type to Null Type is not right.
--
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] liukun4515 commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1163857942
Please hold this pr can don't merge it.
I think we need to discuss some rules about casting.
@alamb @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] liukun4515 commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1167084641
thank you all!!
--
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 #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904128739
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
```suggestion
(Decimal(_, _), Null | 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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904454454
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
agree with you @viirya @alamb
I also noticed this problem when I implement casting the Null Type to decimal data type.
You can review this https://github.com/apache/arrow-rs/pull/884 which add the casting from other data type to Null Datatype
My initial thought was that casting other data type to Null Type is not right.
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904455248
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
>
I also check the Spark yesterday, and find this issue.
--
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] alamb commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r905436410
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
I agree with @nevi-me that a preferable way would be:
1. Not allow `type` -> `NULL` in the `cast` and `try_cast` kernels
2. Add some other function (or maybe just add an example on the `cast` documentation pointing at `new_null_array` as the way to "cast" any array to null
I would personally suggest:
1. Add support in this PR to cast Decimal --> Null to be consistent with other `cast` kernels
2. As a follow on PR (perhaps to close https://github.com/apache/arrow-rs/issues/1923) we can then remove the `type` -> `NULL` casts
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
I agree with @nevi-me that a preferable way would be:
1. Not allow `type` -> `NULL` in the `cast` and `try_cast` kernels
2. Add some other function (or maybe just add an example on the `cast` documentation pointing at `new_null_array` as the way to "cast" any array to null)
I would personally suggest:
1. Add support in this PR to cast Decimal --> Null to be consistent with other `cast` kernels
2. As a follow on PR (perhaps to close https://github.com/apache/arrow-rs/issues/1923) we can then remove the `type` -> `NULL` casts
--
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] liukun4515 commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1163285090
IT failure: https://github.com/apache/arrow-rs/runs/7006919197?check_suite_focus=true#step:6:12919
```
Testing file auth:basic_proto
==========================================================
Traceback (most recent call last):
File "/arrow/dev/archery/archery/integration/runner.py", line 246, in _run_ipc_test_case
run_binaries(producer, consumer, test_case)
File "/arrow/dev/archery/archery/integration/runner.py", line 286, in _produce_consume
consumer.stream_to_file(producer_stream_path, consumer_file_path)
File "/arrow/dev/archery/archery/integration/tester_csharp.py", line 63, in stream_to_file
self.run_shell_command(cmd)
File "/arrow/dev/archery/archery/integration/tester.py", line 49, in run_shell_command
subprocess.check_call(cmd, shell=True)
File "/opt/conda/envs/arrow/lib/python3.10/subprocess.py", line 369, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '/arrow/csharp/artifacts/Apache.Arrow.IntegrationTest/Debug/net6.0/Apache.Arrow.IntegrationTest --mode stream-to-file -a /tmp/tmpawjt5bid/9e0ef030_generated_datetime.consumer_stream_as_file < /tmp/tmpawjt5bid/9e0ef030_generated_datetime.producer_file_as_stream' returned non-zero exit status 1.
################# FAILURES #################
FAILED TEST: datetime Go producing, C# consuming
1 failures
1
```
It has nothing about the arrow-rs
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r903756677
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -4312,6 +4314,24 @@ mod tests {
assert_eq!(array_to_strings(&cast_array), expected);
}
+ #[test]
+ fn test_cast_null_array_to_decimal_array() {
+ let data_type = DataType::Decimal(12, 4);
+ let array = new_null_array(&DataType::Null, 4);
+ assert_eq!(array.data_type(), &DataType::Null);
+ let cast_array = cast(&array, &data_type).expect("cast failed");
+ assert_eq!(cast_array.data_type(), &data_type);
+ for i in 0..4 {
+ assert!(cast_array.is_null(i));
+ }
+
+ // Now: can't convert decimal to NULL type
+ let array = new_null_array(&data_type, 4);
Review Comment:
I will fill up `Decimal to Null` in this pull request.
--
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] liukun4515 commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r904459539
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
I think we can convert Null Data type to other data type, and can't convert other data type to Null Data type.
```
Null can be converted to the INT32(Some(None))
INT32(Some(None) can't be convert to the Null
```
--
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] nevi-me commented on a diff in pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
nevi-me commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r905412286
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
The initial null cast was so that I could write `NullArray` in parquet, which we write as `Int32Array` that's all null.
I think casting null to types is helpful, but other types to null could be a footgun as it causes data loss. So I'd be in favour of removing it. Users who need to do that can always create a separate function that just creates a null array of `array.len()` as it'd have no buffers anyway.
--
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] liukun4515 commented on pull request #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#issuecomment-1165171589
Do we need to merge this into the release 17.0.0?
@alamb @viirya
In the follow-up pr of https://github.com/apache/arrow-datafusion/pull/2764 we need the casting Null to Decimal Data type.
--
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 #1922: Support casting `NULL` to/from `Decimal`
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #1922:
URL: https://github.com/apache/arrow-rs/pull/1922#discussion_r905653851
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -72,9 +72,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
// cast one decimal type to another decimal type
(Decimal(_, _), Decimal(_, _)) => true,
// signed numeric to decimal
- (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
+ (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) |
// decimal to signed numeric
- (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
+ (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64)
Review Comment:
Sounds good to me.
--
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