Skip to content

Commit 05fe095

Browse files
ovralamb
authored andcommitted
ARROW-11570: [Rust] ScalarValue - support Date64
Introduce support for ScalarValue::Date64. Closes #9452 from ovr/issue-11570 Authored-by: Dmitry Patsura <zaets28rus@gmail.com> Signed-off-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent 356c300 commit 05fe095

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

rust/datafusion/src/scalar.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use std::{convert::TryFrom, fmt, iter::repeat, sync::Arc};
2121

2222
use arrow::array::{
23-
Int16Builder, Int32Builder, Int64Builder, Int8Builder, ListBuilder,
23+
Date64Array, Int16Builder, Int32Builder, Int64Builder, Int8Builder, ListBuilder,
2424
TimestampMicrosecondArray, TimestampNanosecondArray, UInt16Builder, UInt32Builder,
2525
UInt64Builder, UInt8Builder,
2626
};
@@ -75,6 +75,8 @@ pub enum ScalarValue {
7575
List(Option<Vec<ScalarValue>>, DataType),
7676
/// Date stored as a signed 32bit int
7777
Date32(Option<i32>),
78+
/// Date stored as a signed 64bit int
79+
Date64(Option<i64>),
7880
/// Timestamp Microseconds
7981
TimeMicrosecond(Option<i64>),
8082
/// Timestamp Nanoseconds
@@ -156,6 +158,7 @@ impl ScalarValue {
156158
DataType::List(Box::new(Field::new("item", data_type.clone(), true)))
157159
}
158160
ScalarValue::Date32(_) => DataType::Date32,
161+
ScalarValue::Date64(_) => DataType::Date64,
159162
ScalarValue::IntervalYearMonth(_) => {
160163
DataType::Interval(IntervalUnit::YearMonth)
161164
}
@@ -329,6 +332,12 @@ impl ScalarValue {
329332
}
330333
None => Arc::new(repeat(None).take(size).collect::<Date32Array>()),
331334
},
335+
ScalarValue::Date64(e) => match e {
336+
Some(value) => {
337+
Arc::new(Date64Array::from_iter_values(repeat(*value).take(size)))
338+
}
339+
None => Arc::new(repeat(None).take(size).collect::<Date64Array>()),
340+
},
332341
ScalarValue::IntervalDayTime(e) => match e {
333342
Some(value) => Arc::new(IntervalDayTimeArray::from_iter_values(
334343
repeat(*value).take(size),
@@ -386,6 +395,9 @@ impl ScalarValue {
386395
DataType::Date32 => {
387396
typed_cast!(array, index, Date32Array, Date32)
388397
}
398+
DataType::Date64 => {
399+
typed_cast!(array, index, Date64Array, Date64)
400+
}
389401
other => {
390402
return Err(DataFusionError::NotImplemented(format!(
391403
"Can't create a scalar of array of type \"{:?}\"",
@@ -580,6 +592,7 @@ impl fmt::Display for ScalarValue {
580592
None => write!(f, "NULL")?,
581593
},
582594
ScalarValue::Date32(e) => format_option!(f, e)?,
595+
ScalarValue::Date64(e) => format_option!(f, e)?,
583596
ScalarValue::IntervalDayTime(e) => format_option!(f, e)?,
584597
ScalarValue::IntervalYearMonth(e) => format_option!(f, e)?,
585598
};
@@ -609,6 +622,7 @@ impl fmt::Debug for ScalarValue {
609622
ScalarValue::LargeUtf8(Some(_)) => write!(f, "LargeUtf8(\"{}\")", self),
610623
ScalarValue::List(_, _) => write!(f, "List([{}])", self),
611624
ScalarValue::Date32(_) => write!(f, "Date32(\"{}\")", self),
625+
ScalarValue::Date64(_) => write!(f, "Date64(\"{}\")", self),
612626
ScalarValue::IntervalDayTime(_) => {
613627
write!(f, "IntervalDayTime(\"{}\")", self)
614628
}

0 commit comments

Comments
 (0)