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 2021/02/11 13:12:23 UTC

[GitHub] [arrow] nevi-me opened a new pull request #9469: WIP: make null arrays

nevi-me opened a new pull request #9469:
URL: https://github.com/apache/arrow/pull/9469


   This allows creating an array with n null values


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

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



[GitHub] [arrow] ritchie46 commented on pull request #9469: WIP: make null arrays

Posted by GitBox <gi...@apache.org>.
ritchie46 commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-777469478


   Nice, this is something useful!


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

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



[GitHub] [arrow] nevi-me commented on pull request #9469: WIP: make null arrays

Posted by GitBox <gi...@apache.org>.
nevi-me commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-777446881


   @alamb do you mind completing this for me? I'd otherwise only be able to work on it in my evening (GMT+2). The tests pass, but I need to add more tests (on the Arrow side), and complete some of the `unimplemented!()` cases.


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

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



[GitHub] [arrow] Dandandan commented on a change in pull request #9469: WIP: make null arrays

Posted by GitBox <gi...@apache.org>.
Dandandan commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574657328



##########
File path: rust/datafusion/src/physical_plan/parquet.rs
##########
@@ -665,7 +661,7 @@ fn build_statistics_array(
         statistics
     } else {
         // no row group has statistics defined
-        return build_null_array(data_type, statistics_count);
+        return new_array_with_nulls(data_type, statistics_count);

Review comment:
       Not sure whether you want to change it in this PR, but there is some code that could use `new_array_with_nulls` too in the function `to_array_of_size`, which uses this:
   `Arc::new(repeat(None).take(size).collect::<Float64Array>())`
   
   
   




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

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



[GitHub] [arrow] alamb commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574716207



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,174 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array with null slots of `length`

Review comment:
       ```suggestion
   /// Creates a new array of `data_type` of length `length` filled entirely of `NULL` values
   ```




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

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



[GitHub] [arrow] alamb commented on pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-778680108


   FYI @maxburke 


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

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



[GitHub] [arrow] github-actions[bot] commented on pull request #9469: WIP: make null arrays

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-777446279


   <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
     regarding copyright ownership.  The ASF licenses this file
     to you under the Apache License, Version 2.0 (the
     "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
   -->
   
   Thanks for opening a pull request!
   
   Could you open an issue for this pull request on JIRA?
   https://issues.apache.org/jira/browse/ARROW
   
   Then could you also rename pull request title in the following format?
   
       ARROW-${JIRA_ID}: [${COMPONENT}] ${SUMMARY}
   
   See also:
   
     * [Other pull requests](https://github.com/apache/arrow/pulls/)
     * [Contribution Guidelines - How to contribute patches](https://arrow.apache.org/docs/developers/contributing.html#how-to-contribute-patches)
   


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

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



[GitHub] [arrow] jorgecarleitao commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
jorgecarleitao commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574716119



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,174 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array with null slots of `length`
+pub fn new_array_with_nulls(data_type: &DataType, length: usize) -> ArrayRef {

Review comment:
       I prefer `new_null_array`. The dataType arg makes it obvious that this is not the `NullArray`, but is a small thing.




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

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



[GitHub] [arrow] alamb commented on pull request #9469: WIP: make null arrays

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-777572931


   Thanks @nevi-me  -- I will try and give it a look / try in a few hours


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

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



[GitHub] [arrow] nevi-me commented on pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
nevi-me commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-778633075


   @alamb you can merge this so it unblocks your work. If there are further questions, I'm happy to address them in a follow-up PR


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

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



[GitHub] [arrow] nevi-me commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
nevi-me commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574709598



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,174 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array with null slots of `length`
+pub fn new_array_with_nulls(data_type: &DataType, length: usize) -> ArrayRef {

Review comment:
       Are we happy with this name, or should we use `new_null_array`?

##########
File path: rust/arrow/src/array/array.rs
##########
@@ -409,4 +578,42 @@ mod tests {
         assert_eq!(a.len(), 0);
         assert_eq!(a.value_offsets()[0], 0i32);
     }
+
+    #[test]
+    fn test_null_boolean() {
+        let array = new_array_with_nulls(&DataType::Boolean, 9);
+        let a = array.as_any().downcast_ref::<BooleanArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_primitive() {
+        let array = new_array_with_nulls(&DataType::Int32, 9);
+        let a = array.as_any().downcast_ref::<Int32Array>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_variable_sized() {
+        let array = new_array_with_nulls(&DataType::Utf8, 9);
+        let a = array.as_any().downcast_ref::<StringArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);
+    }
+
+    #[test]
+    fn test_null_list_primitive() {
+        let data_type =
+            DataType::List(Box::new(Field::new("item", DataType::Int32, true)));

Review comment:
       There's a soundness hole here, that applies more for parquet. If I created this array as non-nullable, there wouldn't have been an error, even though this doesn't comply with the spec.
   
   @alamb @jorgecarleitao @dandandan should we panic, or should I change the signature to `Result<ArrayRef>` so I can validate this condition?
   
   I'm leaning to a panic, just like we panic on `impl From<ArrayDataRef> for {type}Array`. Wrapping a function that doesn't really error out, in a Result feels like assembing the Avengers for a single villain.




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

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



[GitHub] [arrow] alamb commented on pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-778679971


   Thanks @nevi-me  -- I think this is ready to go then. Thanks again!


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

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



[GitHub] [arrow] nevi-me commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
nevi-me commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574729324



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,174 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array with null slots of `length`
+pub fn new_array_with_nulls(data_type: &DataType, length: usize) -> ArrayRef {

Review comment:
       I'll go with `new_null_array` as it's also similar to `new_empty_array`. Thanks




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

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



[GitHub] [arrow] ritchie46 commented on a change in pull request #9469: WIP: make null arrays

Posted by GitBox <gi...@apache.org>.
ritchie46 commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574510747



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +328,141 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array with null slots of `length`
+pub fn new_array_with_nulls(data_type: &DataType, length: usize) -> ArrayRef {
+    let null_buf = Buffer::from(vec![0u8; bit_util::ceil(length, 8)]);

Review comment:
       Could something like this reduce a unnecessary copy?
   
   ```rust
   let null_buff = MutableBuffer::new_null(length).into();
   ```




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

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



[GitHub] [arrow] alamb closed pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb closed pull request #9469:
URL: https://github.com/apache/arrow/pull/9469


   


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

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



[GitHub] [arrow] alamb commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574760259



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,167 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array of `data_type` of length `length` filled entirely of `NULL` values
+pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
+    match data_type {
+        DataType::Null => Arc::new(NullArray::new(length)),
+        DataType::Boolean => {
+            let null_buf: Buffer = MutableBuffer::new_null(length).into();
+            make_array(Arc::new(ArrayData::new(
+                data_type.clone(),
+                length,
+                Some(length),
+                Some(null_buf.clone()),
+                0,
+                vec![null_buf],
+                vec![],
+            )))
+        }
+        DataType::Int8 | DataType::UInt8 => {
+            new_null_sized_array::<Int8Type>(data_type, length)
+        }
+        DataType::Int16 | DataType::UInt16 => {
+            new_null_sized_array::<Int16Type>(data_type, length)
+        }
+        DataType::Float16 => unreachable!(),
+        DataType::Int32
+        | DataType::UInt32
+        | DataType::Float32
+        | DataType::Date32
+        | DataType::Time32(_) => new_null_sized_array::<Int32Type>(data_type, length),
+        DataType::Int64
+        | DataType::UInt64
+        | DataType::Float64
+        | DataType::Date64
+        | DataType::Timestamp(_, _)
+        | DataType::Time64(_)
+        | DataType::Duration(_) => new_null_sized_array::<Int64Type>(data_type, length),
+        DataType::Interval(unit) => match unit {
+            IntervalUnit::YearMonth => {
+                new_null_sized_array::<Int32Type>(data_type, length)
+            }
+            IntervalUnit::DayTime => new_null_sized_array::<Int64Type>(data_type, length),
+        },
+        DataType::FixedSizeBinary(value_len) => make_array(Arc::new(ArrayData::new(
+            data_type.clone(),
+            length,
+            Some(length),
+            Some(MutableBuffer::new_null(length).into()),
+            0,
+            vec![Buffer::from(vec![0u8; *value_len as usize * length])],
+            vec![],
+        ))),
+        DataType::Binary | DataType::Utf8 => {
+            new_null_binary_array::<i32>(data_type, length)
+        }
+        DataType::LargeBinary | DataType::LargeUtf8 => {
+            new_null_binary_array::<i64>(data_type, length)
+        }
+        DataType::List(field) => {
+            new_null_list_array::<i32>(data_type, field.data_type(), length)
+        }
+        DataType::LargeList(field) => {
+            new_null_list_array::<i64>(data_type, field.data_type(), length)
+        }
+        DataType::FixedSizeList(field, value_len) => {
+            make_array(Arc::new(ArrayData::new(
+                data_type.clone(),
+                length,
+                Some(length),
+                Some(MutableBuffer::new_null(length).into()),
+                0,
+                vec![],
+                vec![
+                    new_null_array(field.data_type(), *value_len as usize * length)
+                        .data(),
+                ],
+            )))
+        }
+        DataType::Struct(fields) => make_array(Arc::new(ArrayData::new(
+            data_type.clone(),
+            length,
+            Some(length),
+            Some(MutableBuffer::new_null(length).into()),
+            0,
+            vec![],
+            fields
+                .iter()
+                .map(|field| Arc::new(ArrayData::new_empty(field.data_type())))
+                .collect(),
+        ))),
+        DataType::Union(_) => {
+            unimplemented!("Creating null Union array not yet supported")
+        }
+        DataType::Dictionary(_, value) => {
+            make_array(Arc::new(ArrayData::new(
+                data_type.clone(),
+                length,
+                Some(length),
+                Some(MutableBuffer::new_null(length).into()),
+                0,
+                vec![MutableBuffer::new(0).into()], // keys are empty

Review comment:
       ```suggestion
                   vec![MutableBuffer::new(0).into()], // values are empty
   ```




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

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



[GitHub] [arrow] github-actions[bot] commented on pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-777679480


   https://issues.apache.org/jira/browse/ARROW-11599


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

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



[GitHub] [arrow] jorgecarleitao commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
jorgecarleitao commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574717129



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -409,4 +578,42 @@ mod tests {
         assert_eq!(a.len(), 0);
         assert_eq!(a.value_offsets()[0], 0i32);
     }
+
+    #[test]
+    fn test_null_boolean() {
+        let array = new_array_with_nulls(&DataType::Boolean, 9);
+        let a = array.as_any().downcast_ref::<BooleanArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_primitive() {
+        let array = new_array_with_nulls(&DataType::Int32, 9);
+        let a = array.as_any().downcast_ref::<Int32Array>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_variable_sized() {
+        let array = new_array_with_nulls(&DataType::Utf8, 9);
+        let a = array.as_any().downcast_ref::<StringArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);
+    }
+
+    #[test]
+    fn test_null_list_primitive() {
+        let data_type =
+            DataType::List(Box::new(Field::new("item", DataType::Int32, true)));

Review comment:
       yeah, that hole exists in so many places, unfortunately. Since `ArrayData` has a `null_count`, we have been relying on it for this.
   
   Technically, this goes back to the issue that we are not performing any validation whether the datatype is consistent with the array's content. :(




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

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



[GitHub] [arrow] alamb commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574715077



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -409,4 +578,42 @@ mod tests {
         assert_eq!(a.len(), 0);
         assert_eq!(a.value_offsets()[0], 0i32);
     }
+
+    #[test]
+    fn test_null_boolean() {
+        let array = new_array_with_nulls(&DataType::Boolean, 9);
+        let a = array.as_any().downcast_ref::<BooleanArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_primitive() {
+        let array = new_array_with_nulls(&DataType::Int32, 9);
+        let a = array.as_any().downcast_ref::<Int32Array>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_variable_sized() {
+        let array = new_array_with_nulls(&DataType::Utf8, 9);
+        let a = array.as_any().downcast_ref::<StringArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);
+    }
+
+    #[test]
+    fn test_null_list_primitive() {
+        let data_type =
+            DataType::List(Box::new(Field::new("item", DataType::Int32, true)));

Review comment:
       I vote `panic` for now if you think it is a logic error that a user should be avoiding anyways.
   
   Or alternately, we can make it `panic` now and `Result` later if someone finds a need




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

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



[GitHub] [arrow] codecov-io commented on pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#issuecomment-778569205


   # [Codecov](https://codecov.io/gh/apache/arrow/pull/9469?src=pr&el=h1) Report
   > Merging [#9469](https://codecov.io/gh/apache/arrow/pull/9469?src=pr&el=desc) (8c45e47) into [master](https://codecov.io/gh/apache/arrow/commit/7660a22090fcf1d0230ca1e700a4b98f647b0c48?el=desc) (7660a22) will **decrease** coverage by `0.03%`.
   > The diff coverage is `56.86%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/arrow/pull/9469/graphs/tree.svg?width=650&height=150&src=pr&token=LpTCFbqVT1)](https://codecov.io/gh/apache/arrow/pull/9469?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #9469      +/-   ##
   ==========================================
   - Coverage   82.31%   82.28%   -0.04%     
   ==========================================
     Files         234      234              
     Lines       54482    54594     +112     
   ==========================================
   + Hits        44849    44920      +71     
   - Misses       9633     9674      +41     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow/pull/9469?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [rust/datafusion/src/scalar.rs](https://codecov.io/gh/apache/arrow/pull/9469/diff?src=pr&el=tree#diff-cnVzdC9kYXRhZnVzaW9uL3NyYy9zY2FsYXIucnM=) | `56.73% <15.00%> (+1.04%)` | :arrow_up: |
   | [rust/arrow/src/array/array.rs](https://codecov.io/gh/apache/arrow/pull/9469/diff?src=pr&el=tree#diff-cnVzdC9hcnJvdy9zcmMvYXJyYXkvYXJyYXkucnM=) | `75.50% <62.99%> (-13.03%)` | :arrow_down: |
   | [rust/arrow/src/array/null.rs](https://codecov.io/gh/apache/arrow/pull/9469/diff?src=pr&el=tree#diff-cnVzdC9hcnJvdy9zcmMvYXJyYXkvbnVsbC5ycw==) | `87.50% <66.66%> (-5.10%)` | :arrow_down: |
   | [rust/datafusion/src/physical\_plan/parquet.rs](https://codecov.io/gh/apache/arrow/pull/9469/diff?src=pr&el=tree#diff-cnVzdC9kYXRhZnVzaW9uL3NyYy9waHlzaWNhbF9wbGFuL3BhcnF1ZXQucnM=) | `88.05% <66.66%> (-0.06%)` | :arrow_down: |
   | [rust/arrow/src/array/equal/utils.rs](https://codecov.io/gh/apache/arrow/pull/9469/diff?src=pr&el=tree#diff-cnVzdC9hcnJvdy9zcmMvYXJyYXkvZXF1YWwvdXRpbHMucnM=) | `76.47% <0.00%> (+0.98%)` | :arrow_up: |
   | [rust/arrow/src/array/transform/fixed\_binary.rs](https://codecov.io/gh/apache/arrow/pull/9469/diff?src=pr&el=tree#diff-cnVzdC9hcnJvdy9zcmMvYXJyYXkvdHJhbnNmb3JtL2ZpeGVkX2JpbmFyeS5ycw==) | `84.21% <0.00%> (+5.26%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow/pull/9469?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/arrow/pull/9469?src=pr&el=footer). Last update [7660a22...8c45e47](https://codecov.io/gh/apache/arrow/pull/9469?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


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

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



[GitHub] [arrow] alamb commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574762596



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -409,4 +571,42 @@ mod tests {
         assert_eq!(a.len(), 0);
         assert_eq!(a.value_offsets()[0], 0i32);
     }
+
+    #[test]
+    fn test_null_boolean() {
+        let array = new_null_array(&DataType::Boolean, 9);
+        let a = array.as_any().downcast_ref::<BooleanArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_primitive() {
+        let array = new_null_array(&DataType::Int32, 9);
+        let a = array.as_any().downcast_ref::<Int32Array>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_variable_sized() {
+        let array = new_null_array(&DataType::Utf8, 9);
+        let a = array.as_any().downcast_ref::<StringArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);

Review comment:
       ```suggestion
           assert_eq!(a.value_offsets()[9], 0i32);
           for i in 0..9 {
               assert!(a.is_null(i));
           }
   ```

##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,167 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array of `data_type` of length `length` filled entirely of `NULL` values
+pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
+    match data_type {
+        DataType::Null => Arc::new(NullArray::new(length)),
+        DataType::Boolean => {
+            let null_buf: Buffer = MutableBuffer::new_null(length).into();
+            make_array(Arc::new(ArrayData::new(
+                data_type.clone(),
+                length,
+                Some(length),
+                Some(null_buf.clone()),
+                0,
+                vec![null_buf],
+                vec![],
+            )))
+        }
+        DataType::Int8 | DataType::UInt8 => {
+            new_null_sized_array::<Int8Type>(data_type, length)
+        }
+        DataType::Int16 | DataType::UInt16 => {
+            new_null_sized_array::<Int16Type>(data_type, length)
+        }
+        DataType::Float16 => unreachable!(),
+        DataType::Int32
+        | DataType::UInt32

Review comment:
       While it is probably ok, it took me a while to convince myself that `new_null_sized_array::<Int32Type>` was ok to use for different types like `Float32`
   
   I wonder if it would be better to explicitly list out the types here 
   ```
    DataType::Float32 => new_null_sized_array::<Float32Type>(data_type, length),
    DataType::Date32 => new_null_sized_array::<Int32Type>(data_type, length),
   ...
   ```
   

##########
File path: rust/datafusion/src/scalar.rs
##########
@@ -218,99 +205,90 @@ impl ScalarValue {
                 Some(value) => {
                     Arc::new(Float64Array::from_iter_values(repeat(*value).take(size)))
                 }
-                None => Arc::new(repeat(None).take(size).collect::<Float64Array>()),

Review comment:
       this is a nice cleanup

##########
File path: rust/arrow/src/array/array.rs
##########
@@ -409,4 +571,42 @@ mod tests {
         assert_eq!(a.len(), 0);
         assert_eq!(a.value_offsets()[0], 0i32);
     }
+
+    #[test]
+    fn test_null_boolean() {
+        let array = new_null_array(&DataType::Boolean, 9);
+        let a = array.as_any().downcast_ref::<BooleanArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_primitive() {
+        let array = new_null_array(&DataType::Int32, 9);
+        let a = array.as_any().downcast_ref::<Int32Array>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_variable_sized() {
+        let array = new_null_array(&DataType::Utf8, 9);
+        let a = array.as_any().downcast_ref::<StringArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);
+    }
+
+    #[test]
+    fn test_null_list_primitive() {
+        let data_type =
+            DataType::List(Box::new(Field::new("item", DataType::Int32, true)));
+        let array = new_null_array(&data_type, 9);
+        let a = array.as_any().downcast_ref::<ListArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);
+    }

Review comment:
       ```suggestion
       }
       
       #[test]
       fn test_null_dictionary() {
           let values = vec![
               None, None, None, None, None, None, None, None, None
           ] as Vec<Option<&str>>;
   
           let array : DictionaryArray<Int8Type> = values.into_iter().collect();
           let array = Arc::new(array) as ArrayRef;
   
           let null_array = new_null_array(array.data_type(), 9);
           assert_eq!(&array, &null_array);
       }
   
   ```

##########
File path: rust/arrow/src/array/array.rs
##########
@@ -409,4 +571,42 @@ mod tests {
         assert_eq!(a.len(), 0);
         assert_eq!(a.value_offsets()[0], 0i32);
     }
+
+    #[test]
+    fn test_null_boolean() {
+        let array = new_null_array(&DataType::Boolean, 9);
+        let a = array.as_any().downcast_ref::<BooleanArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_primitive() {
+        let array = new_null_array(&DataType::Int32, 9);
+        let a = array.as_any().downcast_ref::<Int32Array>().unwrap();
+        assert_eq!(a.len(), 9);
+        for i in 0..9 {
+            assert!(a.is_null(i));
+        }
+    }
+
+    #[test]
+    fn test_null_variable_sized() {
+        let array = new_null_array(&DataType::Utf8, 9);
+        let a = array.as_any().downcast_ref::<StringArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);
+    }
+
+    #[test]
+    fn test_null_list_primitive() {
+        let data_type =
+            DataType::List(Box::new(Field::new("item", DataType::Int32, true)));
+        let array = new_null_array(&data_type, 9);
+        let a = array.as_any().downcast_ref::<ListArray>().unwrap();
+        assert_eq!(a.len(), 9);
+        assert_eq!(a.value_offsets()[9], 0i32);

Review comment:
       ```suggestion
           assert_eq!(a.value_offsets()[9], 0i32);
           for i in 0..9 {
               assert!(a.is_null(i));
           }
   ```




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

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



[GitHub] [arrow] jorgecarleitao commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
jorgecarleitao commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574865169



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,167 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array of `data_type` of length `length` filled entirely of `NULL` values
+pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
+    match data_type {
+        DataType::Null => Arc::new(NullArray::new(length)),
+        DataType::Boolean => {
+            let null_buf: Buffer = MutableBuffer::new_null(length).into();
+            make_array(Arc::new(ArrayData::new(
+                data_type.clone(),
+                length,
+                Some(length),
+                Some(null_buf.clone()),
+                0,
+                vec![null_buf],
+                vec![],
+            )))
+        }
+        DataType::Int8 | DataType::UInt8 => {
+            new_null_sized_array::<Int8Type>(data_type, length)
+        }
+        DataType::Int16 | DataType::UInt16 => {
+            new_null_sized_array::<Int16Type>(data_type, length)
+        }
+        DataType::Float16 => unreachable!(),
+        DataType::Int32
+        | DataType::UInt32

Review comment:
       FWIW, imo we have been doing this incorrectly all along. We currently have one `PrimitiveArray` per logical type (e.g. `Date32`, `Int32`) because there is a one-to-one correspondence between `ArrowPrimitiveType` and `DataType`. This implies that we will never be able to support `Timestamp(_,X)` with `PrimitiveArray`, as that type has many variations (one per time zone).
   
   Having one array type per logical type also makes the whole code less maintainable, because we have to downcast for every variation of the `DataType`, instead of for every variation of the underlying physical type.
   
   IMO we should have 1 `PrimitiveArray` per _physical_ type. I.e. `PrimitiveArray<i32>`, `PrimitiveArray<i64>`, etc. The `DataType` just denotes how the physical values are to be interpreted (logical), not their layout in memory nor any safety considerations (e.g. `&str` vs `&[u8]`).
   
   More generally, a generic parameter `T` represents a variation of the underlying physical / memory layout, and we have been using `PrimitiveArray<T>` to represent the same layout but different logical representations.
   
   This is one of the main changes in the proposal I wrote, on which a primitive array is defined by its physical representation, `PrimitiveArray<i64>` and its logical representation (`DataType`), on which the datatype is a many to one to a physical representation (e.g. `Date32`, `Time32` and `Int32` all map to `i32`).




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

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



[GitHub] [arrow] nevi-me commented on a change in pull request #9469: WIP: make null arrays

Posted by GitBox <gi...@apache.org>.
nevi-me commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574659723



##########
File path: rust/datafusion/src/physical_plan/parquet.rs
##########
@@ -665,7 +661,7 @@ fn build_statistics_array(
         statistics
     } else {
         // no row group has statistics defined
-        return build_null_array(data_type, statistics_count);
+        return new_array_with_nulls(data_type, statistics_count);

Review comment:
       I'll change it, thanks :)




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

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



[GitHub] [arrow] nevi-me commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
nevi-me commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574794038



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,167 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array of `data_type` of length `length` filled entirely of `NULL` values
+pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
+    match data_type {
+        DataType::Null => Arc::new(NullArray::new(length)),
+        DataType::Boolean => {
+            let null_buf: Buffer = MutableBuffer::new_null(length).into();
+            make_array(Arc::new(ArrayData::new(
+                data_type.clone(),
+                length,
+                Some(length),
+                Some(null_buf.clone()),
+                0,
+                vec![null_buf],
+                vec![],
+            )))
+        }
+        DataType::Int8 | DataType::UInt8 => {
+            new_null_sized_array::<Int8Type>(data_type, length)
+        }
+        DataType::Int16 | DataType::UInt16 => {
+            new_null_sized_array::<Int16Type>(data_type, length)
+        }
+        DataType::Float16 => unreachable!(),
+        DataType::Int32
+        | DataType::UInt32

Review comment:
       I can change them, seemed tedious though because f32 and i32 use the same underlying size. I was looking for a convenient way of getting the byte size




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

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



[GitHub] [arrow] alamb commented on a change in pull request #9469: ARROW-11599: [Rust] Add function to create array with all nulls

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574715774



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,174 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
     let data = ArrayData::new_empty(data_type);
     make_array(Arc::new(data))
 }
+/// Creates a new array with null slots of `length`
+pub fn new_array_with_nulls(data_type: &DataType, length: usize) -> ArrayRef {

Review comment:
       what about `new_array_of_nulls` ? 
   
   `new_null_array` might be confusing because it *might* be referring to `NullArray`.




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

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