This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 05fe095 ARROW-11570: [Rust] ScalarValue - support Date64
05fe095 is described below
commit 05fe095b2145fbdd4d6ccc6f74b16cba0a21749f
Author: Dmitry Patsura <[email protected]>
AuthorDate: Thu Feb 11 17:01:42 2021 -0500
ARROW-11570: [Rust] ScalarValue - support Date64
Introduce support for ScalarValue::Date64.
Closes #9452 from ovr/issue-11570
Authored-by: Dmitry Patsura <[email protected]>
Signed-off-by: Andrew Lamb <[email protected]>
---
rust/datafusion/src/scalar.rs | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/rust/datafusion/src/scalar.rs b/rust/datafusion/src/scalar.rs
index 31ca1da..d5a6c14 100644
--- a/rust/datafusion/src/scalar.rs
+++ b/rust/datafusion/src/scalar.rs
@@ -20,7 +20,7 @@
use std::{convert::TryFrom, fmt, iter::repeat, sync::Arc};
use arrow::array::{
- Int16Builder, Int32Builder, Int64Builder, Int8Builder, ListBuilder,
+ Date64Array, Int16Builder, Int32Builder, Int64Builder, Int8Builder,
ListBuilder,
TimestampMicrosecondArray, TimestampNanosecondArray, UInt16Builder,
UInt32Builder,
UInt64Builder, UInt8Builder,
};
@@ -75,6 +75,8 @@ pub enum ScalarValue {
List(Option<Vec<ScalarValue>>, DataType),
/// Date stored as a signed 32bit int
Date32(Option<i32>),
+ /// Date stored as a signed 64bit int
+ Date64(Option<i64>),
/// Timestamp Microseconds
TimeMicrosecond(Option<i64>),
/// Timestamp Nanoseconds
@@ -156,6 +158,7 @@ impl ScalarValue {
DataType::List(Box::new(Field::new("item", data_type.clone(),
true)))
}
ScalarValue::Date32(_) => DataType::Date32,
+ ScalarValue::Date64(_) => DataType::Date64,
ScalarValue::IntervalYearMonth(_) => {
DataType::Interval(IntervalUnit::YearMonth)
}
@@ -329,6 +332,12 @@ impl ScalarValue {
}
None =>
Arc::new(repeat(None).take(size).collect::<Date32Array>()),
},
+ ScalarValue::Date64(e) => match e {
+ Some(value) => {
+
Arc::new(Date64Array::from_iter_values(repeat(*value).take(size)))
+ }
+ None =>
Arc::new(repeat(None).take(size).collect::<Date64Array>()),
+ },
ScalarValue::IntervalDayTime(e) => match e {
Some(value) => Arc::new(IntervalDayTimeArray::from_iter_values(
repeat(*value).take(size),
@@ -386,6 +395,9 @@ impl ScalarValue {
DataType::Date32 => {
typed_cast!(array, index, Date32Array, Date32)
}
+ DataType::Date64 => {
+ typed_cast!(array, index, Date64Array, Date64)
+ }
other => {
return Err(DataFusionError::NotImplemented(format!(
"Can't create a scalar of array of type \"{:?}\"",
@@ -580,6 +592,7 @@ impl fmt::Display for ScalarValue {
None => write!(f, "NULL")?,
},
ScalarValue::Date32(e) => format_option!(f, e)?,
+ ScalarValue::Date64(e) => format_option!(f, e)?,
ScalarValue::IntervalDayTime(e) => format_option!(f, e)?,
ScalarValue::IntervalYearMonth(e) => format_option!(f, e)?,
};
@@ -609,6 +622,7 @@ impl fmt::Debug for ScalarValue {
ScalarValue::LargeUtf8(Some(_)) => write!(f, "LargeUtf8(\"{}\")",
self),
ScalarValue::List(_, _) => write!(f, "List([{}])", self),
ScalarValue::Date32(_) => write!(f, "Date32(\"{}\")", self),
+ ScalarValue::Date64(_) => write!(f, "Date64(\"{}\")", self),
ScalarValue::IntervalDayTime(_) => {
write!(f, "IntervalDayTime(\"{}\")", self)
}