Skip to content

Commit 226874e

Browse files
authored
Actually ergonomic timestamp options (#6247)
Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent 65fee09 commit 226874e

8 files changed

Lines changed: 12 additions & 12 deletions

File tree

vortex-array/src/arrays/datetime/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn test_timestamp() {
161161
);
162162
assert_eq!(
163163
temporal_array.temporal_metadata(),
164-
TemporalMetadata::Timestamp((&unit, &tz))
164+
TemporalMetadata::Timestamp(&unit, &tz)
165165
);
166166
}
167167
}

vortex-array/src/arrow/executor/temporal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(super) fn to_arrow_temporal(
7676
DataType::Time64(ArrowTimeUnit::Nanosecond),
7777
) => to_temporal::<Time64NanosecondType>(array, ctx),
7878

79-
(TemporalMetadata::Timestamp((unit, tz)), DataType::Timestamp(arrow_unit, arrow_tz)) => {
79+
(TemporalMetadata::Timestamp(unit, tz), DataType::Timestamp(arrow_unit, arrow_tz)) => {
8080
vortex_ensure!(
8181
tz == arrow_tz,
8282
"Cannot convert {} array to Arrow type {} due to timezone mismatch",

vortex-datafusion/src/convert/scalars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl TryToDataFusion<ScalarValue> for Scalar {
125125
// temporal physical types.
126126
let pv = storage_scalar.as_primitive();
127127
match temporal {
128-
TemporalMetadata::Timestamp((unit, tz)) => match unit {
128+
TemporalMetadata::Timestamp(unit, tz) => match unit {
129129
TimeUnit::Nanoseconds => {
130130
ScalarValue::TimestampNanosecond(pv.as_::<i64>(), tz.clone())
131131
}

vortex-dtype/src/arrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl DType {
301301
// Try and match against the known extension DTypes.
302302
if let Some(temporal) = ext_dtype.metadata_opt::<AnyTemporal>() {
303303
return Ok(match temporal {
304-
TemporalMetadata::Timestamp((unit, tz)) => {
304+
TemporalMetadata::Timestamp(unit, tz) => {
305305
DataType::Timestamp(ArrowTimeUnit::try_from(*unit)?, tz.clone())
306306
}
307307
TemporalMetadata::Date(unit) => match unit {

vortex-dtype/src/datetime/matcher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Matcher for AnyTemporal {
2222

2323
fn try_match<'a>(item: &'a ExtDTypeRef) -> Option<Self::Match<'a>> {
2424
if let Some(opts) = item.metadata_opt::<Timestamp>() {
25-
return Some(TemporalMetadata::Timestamp((&opts.unit, &opts.tz)));
25+
return Some(TemporalMetadata::Timestamp(&opts.unit, &opts.tz));
2626
}
2727
if let Some(opts) = item.metadata_opt::<Date>() {
2828
return Some(TemporalMetadata::Date(opts));
@@ -38,7 +38,7 @@ impl Matcher for AnyTemporal {
3838
#[derive(Debug, PartialEq, Eq)]
3939
pub enum TemporalMetadata<'a> {
4040
/// Metadata for Timestamp dtypes, a tuple of time unit and optional timezone.
41-
Timestamp((&'a TimeUnit, &'a Option<Arc<str>>)),
41+
Timestamp(&'a TimeUnit, &'a Option<Arc<str>>),
4242
/// Metadata for Date dtypes
4343
Date(&'a <Date as ExtDTypeVTable>::Metadata),
4444
/// Metadata for Time dtypes
@@ -53,7 +53,7 @@ impl TemporalMetadata<'_> {
5353
match self {
5454
TemporalMetadata::Time(unit) => **unit,
5555
TemporalMetadata::Date(unit) => **unit,
56-
TemporalMetadata::Timestamp((unit, _tz)) => **unit,
56+
TemporalMetadata::Timestamp(unit, _tz) => **unit,
5757
}
5858
}
5959

@@ -66,7 +66,7 @@ impl TemporalMetadata<'_> {
6666
TemporalMetadata::Date(unit) => Ok(TemporalJiff::Date(
6767
jiff::civil::Date::new(1970, 1, 1)?.checked_add(unit.to_jiff_span(v)?)?,
6868
)),
69-
TemporalMetadata::Timestamp((unit, tz)) => match tz {
69+
TemporalMetadata::Timestamp(unit, tz) => match tz {
7070
None => Ok(TemporalJiff::Unzoned(
7171
jiff::civil::DateTime::new(1970, 1, 1, 0, 0, 0, 0)?
7272
.checked_add(unit.to_jiff_span(v)?)?,

vortex-duckdb/src/convert/dtype.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ impl TryFrom<&DType> for LogicalType {
235235
};
236236

237237
match temporal {
238-
TemporalMetadata::Timestamp((unit, None)) => match unit {
238+
TemporalMetadata::Timestamp(unit, None) => match unit {
239239
TimeUnit::Nanoseconds => DUCKDB_TYPE::DUCKDB_TYPE_TIMESTAMP_NS,
240240
TimeUnit::Microseconds => DUCKDB_TYPE::DUCKDB_TYPE_TIMESTAMP,
241241
TimeUnit::Milliseconds => DUCKDB_TYPE::DUCKDB_TYPE_TIMESTAMP_MS,
242242
TimeUnit::Seconds => DUCKDB_TYPE::DUCKDB_TYPE_TIMESTAMP_S,
243243
_ => vortex_bail!("Invalid TimeUnit {} for timestamp", unit),
244244
},
245-
TemporalMetadata::Timestamp((unit, Some(tz))) => {
245+
TemporalMetadata::Timestamp(unit, Some(tz)) => {
246246
if tz.as_ref() != "UTC" {
247247
vortex_bail!("Invalid timezone for timestamp_tz {tz}, must be UTC");
248248
}

vortex-duckdb/src/convert/scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl ToDuckDBScalar for ExtScalar<'_> {
182182
};
183183

184184
Ok(match temporal {
185-
TemporalMetadata::Timestamp((unit, tz)) => {
185+
TemporalMetadata::Timestamp(unit, tz) => {
186186
if let Some(tz) = tz.as_ref() {
187187
if tz.as_ref() != "UTC" {
188188
// TODO(ngates): we should convert into UTC as DuckDB does internally.

vortex-scalar/src/arrow/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl TryFrom<&Scalar> for Arc<dyn Datum> {
133133
.ok_or_else(|| vortex_err!("Expected primitive scalar"))?;
134134

135135
match temporal {
136-
TemporalMetadata::Timestamp((unit, tz)) => {
136+
TemporalMetadata::Timestamp(unit, tz) => {
137137
let value = primitive.as_::<i64>();
138138
match unit {
139139
TimeUnit::Nanoseconds => {

0 commit comments

Comments
 (0)