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/04/15 20:04:58 UTC

[GitHub] [arrow-rs] WinkerDu opened a new pull request, #1572: allow casting `DataType::Null` from and to others

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

   # 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 #684.
   
   # 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.
   -->
   Casting from `DataType::Null` to many other types is not allowed for now, like `DataType::Null` <-> `DataType::Utf8`, [apache/arrow-datafusion#1188](https://github.com/apache/arrow-datafusion/issues/1188) depends on this casting ability to solve `NULL` constant issue in function call
   
   # 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.
   -->
   Allow casting `DataType::Null` from and to most of types except for `DataType::Union` and `DataType::Decimal`, which is not supported in `new_null_array`
   
   # Are there any user-facing changes?
   
   No.
   <!---
   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 pull request #1572: Support casting to/from `DataType::Null` in `cast` kernel

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572#issuecomment-1101740104

   Thanks @yjshen  ❤️ 


-- 
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] WinkerDu commented on pull request #1572: allow casting `DataType::Null` from and to others

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572#issuecomment-1100792266

   cc @alamb @Dandandan  PTAL, thank you.


-- 
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] WinkerDu commented on pull request #1572: allow casting `DataType::Null` from and to others

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572#issuecomment-1100737710

   @tustvold 
   A follow up commit pushed:
   - more test cases added
   - check `cast_from_and_to_null` from macro to function
   
   Please approve the running workflows and have another review, thank you :)


-- 
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] WinkerDu commented on pull request #1572: allow casting `DataType::Null` from and to others

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572#issuecomment-1100363576

   @alamb @Dandandan plz approve the running workflows, thank you.


-- 
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 commented on a diff in pull request #1572: allow casting `DataType::Null` from and to others

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572#discussion_r851646257


##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -4238,6 +4290,76 @@ mod tests {
 
         typed_test!(Float32Array, Float32, Float32Type);
         typed_test!(Float64Array, Float64, Float64Type);
+
+        typed_test!(Date32Array, Date32, Date32Type);
+        typed_test!(Date64Array, Date64, Date64Type);
+    }
+
+    macro_rules! cast_from_and_to_null {

Review Comment:
   Does this need to be a macro, I think a function would be clearer and easier to debug. Might also have teeny compile-time benefit 😆  



##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -4238,6 +4290,76 @@ mod tests {
 
         typed_test!(Float32Array, Float32, Float32Type);
         typed_test!(Float64Array, Float64, Float64Type);
+
+        typed_test!(Date32Array, Date32, Date32Type);
+        typed_test!(Date64Array, Date64, Date64Type);
+    }
+
+    macro_rules! cast_from_and_to_null {
+        ($TYPE:ident) => {{
+            let array = new_null_array(&$TYPE, 4);
+            assert_eq!(array.data_type(), &$TYPE);
+            let cast_array = cast(&array, &DataType::Null).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &DataType::Null);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }
+        {
+            let array = new_null_array(&DataType::Null, 4);
+            assert_eq!(array.data_type(), &DataType::Null);
+            let cast_array = cast(&array, &$TYPE).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &$TYPE);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }};
+    }
+
+    #[test]
+    fn test_cast_null_from_and_to_variable_sized() {
+        let data_type = DataType::Utf8;
+        cast_from_and_to_null!(data_type);
+
+        let data_type = DataType::LargeUtf8;
+        cast_from_and_to_null!(data_type);
+
+        let data_type = DataType::Binary;

Review Comment:
   LargeBinary also?



##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -4238,6 +4290,76 @@ mod tests {
 
         typed_test!(Float32Array, Float32, Float32Type);
         typed_test!(Float64Array, Float64, Float64Type);
+
+        typed_test!(Date32Array, Date32, Date32Type);
+        typed_test!(Date64Array, Date64, Date64Type);
+    }
+
+    macro_rules! cast_from_and_to_null {
+        ($TYPE:ident) => {{
+            let array = new_null_array(&$TYPE, 4);
+            assert_eq!(array.data_type(), &$TYPE);
+            let cast_array = cast(&array, &DataType::Null).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &DataType::Null);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }
+        {
+            let array = new_null_array(&DataType::Null, 4);
+            assert_eq!(array.data_type(), &DataType::Null);
+            let cast_array = cast(&array, &$TYPE).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &$TYPE);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }};
+    }
+
+    #[test]
+    fn test_cast_null_from_and_to_variable_sized() {

Review Comment:
   Maybe fixed size also whilst here?



##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -487,7 +526,20 @@ pub fn cast_with_options(
             | UInt64
             | Float64
             | Date64
+            | Timestamp(_, _)
+            | Time64(_)
+            | Duration(_)
+            | Interval(_)
+            | FixedSizeBinary(_)
+            | Binary
+            | Utf8
+            | LargeBinary
+            | LargeUtf8
             | List(_)
+            | LargeList(_)
+            | FixedSizeList(_, _)
+            | Struct(_)
+            | Map(_, _)
             | Dictionary(_, _),
             Null,
         ) => Ok(new_null_array(to_type, array.len())),

Review Comment:
   I've confirmed that these types are all supported by [new_null_array](https://github.com/apache/arrow-rs/blob/master/arrow/src/array/array.rs#L440)



##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -4238,6 +4290,76 @@ mod tests {
 
         typed_test!(Float32Array, Float32, Float32Type);
         typed_test!(Float64Array, Float64, Float64Type);
+
+        typed_test!(Date32Array, Date32, Date32Type);
+        typed_test!(Date64Array, Date64, Date64Type);
+    }
+
+    macro_rules! cast_from_and_to_null {
+        ($TYPE:ident) => {{
+            let array = new_null_array(&$TYPE, 4);
+            assert_eq!(array.data_type(), &$TYPE);
+            let cast_array = cast(&array, &DataType::Null).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &DataType::Null);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }
+        {
+            let array = new_null_array(&DataType::Null, 4);
+            assert_eq!(array.data_type(), &DataType::Null);
+            let cast_array = cast(&array, &$TYPE).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &$TYPE);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }};
+    }
+
+    #[test]
+    fn test_cast_null_from_and_to_variable_sized() {
+        let data_type = DataType::Utf8;
+        cast_from_and_to_null!(data_type);
+
+        let data_type = DataType::LargeUtf8;
+        cast_from_and_to_null!(data_type);
+
+        let data_type = DataType::Binary;
+        cast_from_and_to_null!(data_type);
+    }
+
+    #[test]
+    fn test_cast_null_from_and_to_nested_type() {
+        // cast null from and to map
+        let data_type = DataType::Map(
+            Box::new(Field::new(
+                "entry",
+                DataType::Struct(vec![
+                    Field::new("key", DataType::Utf8, false),
+                    Field::new("value", DataType::Int32, true),
+                ]),
+                false,
+            )),
+            false,
+        );
+        cast_from_and_to_null!(data_type);
+
+        // cast null from and to list
+        let data_type =
+            DataType::List(Box::new(Field::new("item", DataType::Int32, true)));

Review Comment:
   LargeList and FixedSizeList?



##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -4238,6 +4290,76 @@ mod tests {
 
         typed_test!(Float32Array, Float32, Float32Type);
         typed_test!(Float64Array, Float64, Float64Type);
+
+        typed_test!(Date32Array, Date32, Date32Type);
+        typed_test!(Date64Array, Date64, Date64Type);
+    }
+
+    macro_rules! cast_from_and_to_null {
+        ($TYPE:ident) => {{
+            let array = new_null_array(&$TYPE, 4);
+            assert_eq!(array.data_type(), &$TYPE);
+            let cast_array = cast(&array, &DataType::Null).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &DataType::Null);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }
+        {
+            let array = new_null_array(&DataType::Null, 4);
+            assert_eq!(array.data_type(), &DataType::Null);
+            let cast_array = cast(&array, &$TYPE).expect("cast failed");
+            assert_eq!(cast_array.data_type(), &$TYPE);
+            for i in 0..4 {
+                assert!(cast_array.is_null(i));
+            }
+        }};
+    }
+
+    #[test]
+    fn test_cast_null_from_and_to_variable_sized() {
+        let data_type = DataType::Utf8;
+        cast_from_and_to_null!(data_type);
+
+        let data_type = DataType::LargeUtf8;
+        cast_from_and_to_null!(data_type);
+
+        let data_type = DataType::Binary;
+        cast_from_and_to_null!(data_type);
+    }
+
+    #[test]
+    fn test_cast_null_from_and_to_nested_type() {
+        // cast null from and to map
+        let data_type = DataType::Map(
+            Box::new(Field::new(
+                "entry",
+                DataType::Struct(vec![
+                    Field::new("key", DataType::Utf8, false),
+                    Field::new("value", DataType::Int32, true),
+                ]),
+                false,
+            )),
+            false,
+        );
+        cast_from_and_to_null!(data_type);
+
+        // cast null from and to list
+        let data_type =
+            DataType::List(Box::new(Field::new("item", DataType::Int32, true)));
+        cast_from_and_to_null!(data_type);
+
+        // cast null from and to dictionary
+        let values = vec![None, None, None, None] as Vec<Option<&str>>;
+        let array: DictionaryArray<Int8Type> = values.into_iter().collect();
+        let array = Arc::new(array) as ArrayRef;
+        let data_type = array.data_type().to_owned();
+        cast_from_and_to_null!(data_type);
+
+        // cast null from and to struct
+        let data_type =
+            DataType::Struct(vec![Field::new("data", DataType::Int64, false)]);
+        cast_from_and_to_null!(data_type);

Review Comment:
   Map?



-- 
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] WinkerDu commented on pull request #1572: Support casting to/from `DataType::Null` in `cast` kernel

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572#issuecomment-1101114635

   @alamb @tustvold Is this pr OK to merge,
   Or can you help @ some other committers to take another look?
   Thank you


-- 
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 #1572: allow casting `DataType::Null` from and to others

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572#issuecomment-1100384579

   # [Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1572?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 [#1572](https://codecov.io/gh/apache/arrow-rs/pull/1572?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e53d7a5) into [master](https://codecov.io/gh/apache/arrow-rs/commit/5dca6f07884745b5839cb91739faefd52f12b02b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5dca6f0) will **increase** coverage by `0.05%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1572      +/-   ##
   ==========================================
   + Coverage   82.87%   82.93%   +0.05%     
   ==========================================
     Files         193      193              
     Lines       55304    55328      +24     
   ==========================================
   + Hits        45835    45884      +49     
   + Misses       9469     9444      -25     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow-rs/pull/1572?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/1572/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.78% <100.00%> (+0.04%)` | :arrow_up: |
   | [parquet\_derive/src/parquet\_field.rs](https://codecov.io/gh/apache/arrow-rs/pull/1572/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-cGFycXVldF9kZXJpdmUvc3JjL3BhcnF1ZXRfZmllbGQucnM=) | `65.98% <0.00%> (-0.46%)` | :arrow_down: |
   | [arrow/src/array/transform/mod.rs](https://codecov.io/gh/apache/arrow-rs/pull/1572/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-YXJyb3cvc3JjL2FycmF5L3RyYW5zZm9ybS9tb2QucnM=) | `86.46% <0.00%> (-0.12%)` | :arrow_down: |
   | [parquet/src/encodings/encoding.rs](https://codecov.io/gh/apache/arrow-rs/pull/1572/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-cGFycXVldC9zcmMvZW5jb2RpbmdzL2VuY29kaW5nLnJz) | `93.56% <0.00%> (+0.18%)` | :arrow_up: |
   | [arrow/src/array/array.rs](https://codecov.io/gh/apache/arrow-rs/pull/1572/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-YXJyb3cvc3JjL2FycmF5L2FycmF5LnJz) | `92.70% <0.00%> (+7.03%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1572?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/1572?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 [5dca6f0...e53d7a5](https://codecov.io/gh/apache/arrow-rs/pull/1572?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] yjshen merged pull request #1572: Support casting to/from `DataType::Null` in `cast` kernel

Posted by GitBox <gi...@apache.org>.
yjshen merged PR #1572:
URL: https://github.com/apache/arrow-rs/pull/1572


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