Skip to content

Commit 17816e4

Browse files
committed
support Interval DataType
:) select to_interval('02:01'), to_interval('1 year 1 day 1 hour'); ┌───────────────────────────────────────────────────────────┐ │ to_interval('02:01') │ to_interval('1 year 1 day 1 hour') │ │ Interval │ Interval │ ├──────────────────────┼────────────────────────────────────┤ │ 2:01:00 │ 1year 1day 1:00:00 │ └───────────────────────────────────────────────────────────┘
1 parent ba9aa5f commit 17816e4

File tree

65 files changed

+1813
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1813
-34
lines changed

Cargo.lock

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/column/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ column-default = [
2121
]
2222

2323
[dependencies]
24-
24+
borsh = { workspace = true, features = ["derive"] }
2525
databend-common-base = { workspace = true }
2626
databend-common-exception = { workspace = true }
2727

src/common/column/src/types/native.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ use std::convert::TryFrom;
1717
use std::ops::Neg;
1818
use std::panic::RefUnwindSafe;
1919

20+
use borsh::BorshDeserialize;
21+
use borsh::BorshSerialize;
2022
use bytemuck::Pod;
2123
use bytemuck::Zeroable;
2224
use databend_common_base::base::OrderedFloat;
25+
use num_traits::NumCast;
26+
use num_traits::ToPrimitive;
27+
use serde_derive::Deserialize;
28+
use serde_derive::Serialize;
2329

2430
use super::PrimitiveType;
2531

@@ -243,11 +249,43 @@ impl NativeType for days_ms {
243249
}
244250

245251
/// The in-memory representation of the MonthDayNano variant of the "Interval" logical type.
246-
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash, Zeroable, Pod)]
252+
#[derive(
253+
Debug,
254+
Copy,
255+
Clone,
256+
Default,
257+
PartialEq,
258+
PartialOrd,
259+
Ord,
260+
Eq,
261+
Hash,
262+
Zeroable,
263+
Pod,
264+
Serialize,
265+
Deserialize,
266+
BorshSerialize,
267+
BorshDeserialize,
268+
)]
247269
#[allow(non_camel_case_types)]
248270
#[repr(C)]
249271
pub struct months_days_ns(pub i32, pub i32, pub i64);
250272

273+
impl NumCast for months_days_ns {
274+
fn from<T: ToPrimitive>(n: T) -> Option<Self> {
275+
n.to_i64().map(|n| Self::new(0, 0, n))
276+
}
277+
}
278+
279+
impl ToPrimitive for months_days_ns {
280+
fn to_i64(&self) -> Option<i64> {
281+
Some(self.2)
282+
}
283+
284+
fn to_u64(&self) -> Option<u64> {
285+
self.2.to_u64()
286+
}
287+
}
288+
251289
impl months_days_ns {
252290
/// A new [`months_days_ns`].
253291
#[inline]

0 commit comments

Comments
 (0)