You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2023/06/05 18:43:38 UTC
[arrow-rs] branch master updated: Make PrimitiveArray::with_timezone consuming (#4366)
This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 3e6cf98a7 Make PrimitiveArray::with_timezone consuming (#4366)
3e6cf98a7 is described below
commit 3e6cf98a7b1e54a87a32083a09a351476286e5d4
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Mon Jun 5 19:43:31 2023 +0100
Make PrimitiveArray::with_timezone consuming (#4366)
---
arrow-array/src/array/primitive_array.rs | 17 +++++++----------
parquet/src/arrow/array_reader/primitive_array.rs | 4 ++--
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/arrow-array/src/array/primitive_array.rs b/arrow-array/src/array/primitive_array.rs
index 35202a4c7..3fa011f8e 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -1132,24 +1132,21 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
}
/// Construct a timestamp array with new timezone
- pub fn with_timezone(&self, timezone: impl Into<Arc<str>>) -> Self {
+ pub fn with_timezone(self, timezone: impl Into<Arc<str>>) -> Self {
self.with_timezone_opt(Some(timezone.into()))
}
/// Construct a timestamp array with UTC
- pub fn with_timezone_utc(&self) -> Self {
+ pub fn with_timezone_utc(self) -> Self {
self.with_timezone("+00:00")
}
/// Construct a timestamp array with an optional timezone
- pub fn with_timezone_opt<S: Into<Arc<str>>>(&self, timezone: Option<S>) -> Self {
- let array_data = unsafe {
- self.to_data()
- .into_builder()
- .data_type(DataType::Timestamp(T::UNIT, timezone.map(Into::into)))
- .build_unchecked()
- };
- PrimitiveArray::from(array_data)
+ pub fn with_timezone_opt<S: Into<Arc<str>>>(self, timezone: Option<S>) -> Self {
+ Self {
+ data_type: DataType::Timestamp(T::UNIT, timezone.map(Into::into)),
+ ..self
+ }
}
}
diff --git a/parquet/src/arrow/array_reader/primitive_array.rs b/parquet/src/arrow/array_reader/primitive_array.rs
index ec0d29e8b..f833eccec 100644
--- a/parquet/src/arrow/array_reader/primitive_array.rs
+++ b/parquet/src/arrow/array_reader/primitive_array.rs
@@ -502,7 +502,7 @@ mod tests {
)
.as_str(),
)
- $(.with_timezone($timezone))?
+ $(.clone().with_timezone($timezone))?
;
// create expected array as primitive, and cast to result type
@@ -527,7 +527,7 @@ mod tests {
)
.as_str(),
)
- $(.with_timezone($timezone))?
+ $(.clone().with_timezone($timezone))?
;
assert_eq!(expected, array);
}