LeslieKid commented on code in PR #13041: URL: https://github.com/apache/datafusion/pull/13041#discussion_r1811912447
########## test-utils/src/array_gen/primitive.rs: ########## @@ -54,7 +54,19 @@ impl PrimitiveArrayGenerator { | DataType::UInt32 | DataType::UInt64 | DataType::Float32 - | DataType::Float64 => self.rng.gen::<N>(), + | DataType::Float64 + | DataType::Date32 => self.rng.gen::<N>(), + + DataType::Date64 => { + // TODO: constrain this range to valid dates if necessary + let date_value = self.rng.gen_range(i64::MIN..=i64::MAX); + let millis_per_day: i64 = 86_400_000; + let adjusted_value = date_value - (date_value % millis_per_day); + // SAFETY: here we can convert i64 to N safely since we determine that the type N is i64 + unsafe { + std::ptr::read(&adjusted_value as *const i64 as *const N) + } Review Comment: I have tried to use try_into(). But maybe it requires `N: TryFrom<i64>`? This would limit other primitive types like f32. And because of the `A: ArrowPrimitiveType<Native = N>` and `A::DATA_TYPE` is Date64, I think it can use `unsafe` here as an alternative. -- 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-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org