New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate ArrayData type when converting to Array (#2834) #2835
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
21e6dec
Validate ArrayData type when converting to Array (#2834)
tustvold 102f86f
Fix cast kernel and take kernel tests
tustvold 2fa08ee
Clippy
tustvold 7d73899
Fix parquet
tustvold e900fad
Merge remote-tracking branch 'upstream/master' into validate-array-da…
tustvold a6d9618
Merge remote-tracking branch 'upstream/master' into validate-array-da…
tustvold a2d9865
Merge remote-tracking branch 'upstream/master' into validate-array-da…
tustvold c600114
Merge remote-tracking branch 'upstream/master' into validate-array-da…
tustvold d4266e6
Clippy
tustvold 4f1069b
Merge remote-tracking branch 'upstream/master' into validate-array-da…
tustvold File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,12 +43,12 @@ use std::str; | |
use std::sync::Arc; | ||
|
||
use crate::buffer::MutableBuffer; | ||
use crate::compute::divide_scalar; | ||
use crate::compute::kernels::arithmetic::{divide, multiply}; | ||
use crate::compute::kernels::arity::unary; | ||
use crate::compute::kernels::cast_utils::string_to_timestamp_nanos; | ||
use crate::compute::kernels::temporal::extract_component_from_array; | ||
use crate::compute::kernels::temporal::return_compute_error_with; | ||
use crate::compute::{divide_scalar, multiply_scalar}; | ||
use crate::compute::{try_unary, using_chrono_tz_and_utc_naive_date_time}; | ||
use crate::datatypes::*; | ||
use crate::error::{ArrowError, Result}; | ||
|
@@ -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)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive by cleanup |
||
let array_ref = Arc::new(converted) as ArrayRef; | ||
use TimeUnit::*; | ||
match to_unit { | ||
|
@@ -1284,7 +1284,8 @@ pub fn cast_with_options( | |
Ok(Arc::new(values) as ArrayRef) | ||
} | ||
(Time64(from_unit), Time32(to_unit)) => { | ||
let time_array = Int64Array::from(array.data().clone()); | ||
let array = cast_with_options(array, &Int64, cast_options)?; | ||
let time_array = as_primitive_array::<Int64Type>(array.as_ref()); | ||
let from_size = time_unit_multiple(from_unit); | ||
let to_size = time_unit_multiple(to_unit); | ||
let divisor = from_size / to_size; | ||
|
@@ -1321,18 +1322,16 @@ pub fn cast_with_options( | |
} | ||
} | ||
(Timestamp(from_unit, _), Timestamp(to_unit, _)) => { | ||
let time_array = Int64Array::from(array.data().clone()); | ||
let array = cast_with_options(array, &Int64, cast_options)?; | ||
let time_array = as_primitive_array::<Int64Type>(array.as_ref()); | ||
let from_size = time_unit_multiple(from_unit); | ||
let to_size = time_unit_multiple(to_unit); | ||
// we either divide or multiply, depending on size of each unit | ||
// units are never the same when the types are the same | ||
let converted = if from_size >= to_size { | ||
divide_scalar(&time_array, from_size / to_size)? | ||
} else { | ||
multiply( | ||
&time_array, | ||
&Int64Array::from(vec![to_size / from_size; array.len()]), | ||
)? | ||
multiply_scalar(&time_array, to_size / from_size)? | ||
}; | ||
let array_ref = Arc::new(converted) as ArrayRef; | ||
use TimeUnit::*; | ||
|
@@ -1355,10 +1354,10 @@ pub fn cast_with_options( | |
} | ||
} | ||
(Timestamp(from_unit, _), Date32) => { | ||
let time_array = Int64Array::from(array.data().clone()); | ||
let array = cast_with_options(array, &Int64, cast_options)?; | ||
let time_array = as_primitive_array::<Int64Type>(array.as_ref()); | ||
let from_size = time_unit_multiple(from_unit) * SECONDS_IN_DAY; | ||
|
||
// Int32Array::from_iter(tim.iter) | ||
let mut b = Date32Builder::with_capacity(array.len()); | ||
|
||
for i in 0..array.len() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍