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/10/06 10:58:14 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #2835: Validate ArrayData type when converting to Array (#2834)

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

   # 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 #2834
   
   # 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.
   -->
   
   Arrays can assume that the provided ArrayData is valid, however, what that means depends on the data type of the ArrayData. We weren't always validating that the arrays had the expected data type, which could lead to unsoundness.
   
   # 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] tustvold merged pull request #2835: Validate ArrayData type when converting to Array (#2834)

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


-- 
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 pull request #2835: Validate ArrayData type when converting to Array (#2834)

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

   Interestingly this is failing on timestamp casts, which is very fishy :sweat_smile: 


-- 
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 #2835: Validate ArrayData type when converting to Array (#2834)

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


##########
parquet/src/arrow/array_reader/primitive_array.rs:
##########
@@ -169,15 +170,21 @@ where
             .null_bit_buffer(self.record_reader.consume_bitmap_buffer());
 
         let array_data = unsafe { array_data.build_unchecked() };
-        let array = match T::get_physical_type() {
-            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)) as ArrayRef,
-            PhysicalType::INT32 => Arc::new(Int32Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT64 => Arc::new(Int64Array::from(array_data)) as ArrayRef,
-            PhysicalType::FLOAT => Arc::new(Float32Array::from(array_data)) as ArrayRef,
-            PhysicalType::DOUBLE => Arc::new(Float64Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT96 => {
-                Arc::new(TimestampNanosecondArray::from(array_data)) as ArrayRef
-            }
+        let array: ArrayRef = match T::get_physical_type() {
+            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)),
+            PhysicalType::INT32 => match array_data.data_type() {
+                ArrowType::UInt32 => Arc::new(UInt32Array::from(array_data)),

Review Comment:
   Sort of, it doesn't actually matter as the PrimitiveArray is discarded by the parent StructArrayReader, which is only concerned with the ArrayData portion



-- 
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 pull request #2835: Validate ArrayData type when converting to Array (#2834)

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

   Parquet failure does not appear to relate to this 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.

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 #2835: Validate ArrayData type when converting to Array (#2834)

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


##########
parquet/src/arrow/array_reader/primitive_array.rs:
##########
@@ -169,15 +170,21 @@ where
             .null_bit_buffer(self.record_reader.consume_bitmap_buffer());
 
         let array_data = unsafe { array_data.build_unchecked() };
-        let array = match T::get_physical_type() {
-            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)) as ArrayRef,
-            PhysicalType::INT32 => Arc::new(Int32Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT64 => Arc::new(Int64Array::from(array_data)) as ArrayRef,
-            PhysicalType::FLOAT => Arc::new(Float32Array::from(array_data)) as ArrayRef,
-            PhysicalType::DOUBLE => Arc::new(Float64Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT96 => {
-                Arc::new(TimestampNanosecondArray::from(array_data)) as ArrayRef
-            }
+        let array: ArrayRef = match T::get_physical_type() {
+            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)),
+            PhysicalType::INT32 => match array_data.data_type() {
+                ArrowType::UInt32 => Arc::new(UInt32Array::from(array_data)),

Review Comment:
   Oh, because now it would panic complaining that it was creating an Int32Array from DataType::UInt32 ArrayData.



-- 
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] ursabot commented on pull request #2835: Validate ArrayData type when converting to Array (#2834)

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

   Benchmark runs are scheduled for baseline = 1397fb4a0071b89ec6846762a38da6d279d4152b and contender = 8adebca35253943fffb0653e7521eaf7a25b0153. 8adebca35253943fffb0653e7521eaf7a25b0153 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/412a12825db0427abce264bc14cff1bf...a755cc96e5df456c92dce6485933aaa6/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/be1fc2323aa74f6c850f77241d12309a...afa55aa8a9c5472d8ca9fdf3b76cdd90/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/62153875a9d44557af230210eeb058c1...99794d61d53c486ead524e3ff6f10e21/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/061a85090d72428eb3a61e2abc959cd4...4bf7177ac2e34c0f89e9a01bb16730e9/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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 #2835: Validate ArrayData type when converting to Array (#2834)

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


##########
parquet/src/arrow/array_reader/primitive_array.rs:
##########
@@ -169,15 +170,21 @@ where
             .null_bit_buffer(self.record_reader.consume_bitmap_buffer());
 
         let array_data = unsafe { array_data.build_unchecked() };
-        let array = match T::get_physical_type() {
-            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)) as ArrayRef,
-            PhysicalType::INT32 => Arc::new(Int32Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT64 => Arc::new(Int64Array::from(array_data)) as ArrayRef,
-            PhysicalType::FLOAT => Arc::new(Float32Array::from(array_data)) as ArrayRef,
-            PhysicalType::DOUBLE => Arc::new(Float64Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT96 => {
-                Arc::new(TimestampNanosecondArray::from(array_data)) as ArrayRef
-            }
+        let array: ArrayRef = match T::get_physical_type() {
+            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)),
+            PhysicalType::INT32 => match array_data.data_type() {
+                ArrowType::UInt32 => Arc::new(UInt32Array::from(array_data)),

Review Comment:
   is this a bug fix? Seems like a good improvement to me



##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -201,6 +201,13 @@ impl From<Vec<Option<bool>>> for BooleanArray {
 
 impl From<ArrayData> for BooleanArray {
     fn from(data: ArrayData) -> Self {
+        assert_eq!(
+            data.data_type(),
+            &DataType::Boolean,
+            "BooleanArray expected ArrayData with type {} got {}",

Review Comment:
   👍 



-- 
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 #2835: Validate ArrayData type when converting to Array (#2834)

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


##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -1241,14 +1241,14 @@ pub fn cast_with_options(
         }
         //(Time32(TimeUnit::Second), Time64(_)) => {},
         (Time32(from_unit), Time64(to_unit)) => {
-            let time_array = Int32Array::from(array.data().clone());
+            let array = cast_with_options(array, &Int32, cast_options)?;
+            let time_array = as_primitive_array::<Int32Type>(array.as_ref());
             // note: (numeric_cast + SIMD multiply) is faster than (cast & multiply)
             let c: Int64Array = numeric_cast(&time_array);
             let from_size = time_unit_multiple(from_unit);
             let to_size = time_unit_multiple(to_unit);
             // from is only smaller than to if 64milli/64second don't exist
-            let mult = Int64Array::from(vec![to_size / from_size; array.len()]);
-            let converted = multiply(&c, &mult)?;
+            let converted = multiply_scalar(&c, to_size / from_size)?;

Review Comment:
   Drive by cleanup



-- 
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 #2835: Validate ArrayData type when converting to Array (#2834)

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


##########
parquet/src/arrow/array_reader/primitive_array.rs:
##########
@@ -169,15 +170,21 @@ where
             .null_bit_buffer(self.record_reader.consume_bitmap_buffer());
 
         let array_data = unsafe { array_data.build_unchecked() };
-        let array = match T::get_physical_type() {
-            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)) as ArrayRef,
-            PhysicalType::INT32 => Arc::new(Int32Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT64 => Arc::new(Int64Array::from(array_data)) as ArrayRef,
-            PhysicalType::FLOAT => Arc::new(Float32Array::from(array_data)) as ArrayRef,
-            PhysicalType::DOUBLE => Arc::new(Float64Array::from(array_data)) as ArrayRef,
-            PhysicalType::INT96 => {
-                Arc::new(TimestampNanosecondArray::from(array_data)) as ArrayRef
-            }
+        let array: ArrayRef = match T::get_physical_type() {
+            PhysicalType::BOOLEAN => Arc::new(BooleanArray::from(array_data)),
+            PhysicalType::INT32 => match array_data.data_type() {
+                ArrowType::UInt32 => Arc::new(UInt32Array::from(array_data)),

Review Comment:
   I guess I was wondering "what is the rationale for this change"



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