Skip to content

Commit

Permalink
support Interval DataType
Browse files Browse the repository at this point in the history
:) 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                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  • Loading branch information
TCeason committed Dec 13, 2024
1 parent 85f4771 commit 0ecbfe1
Show file tree
Hide file tree
Showing 65 changed files with 1,808 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/common/column/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ column-default = [
]

[dependencies]

borsh = { workspace = true, features = ["derive"] }
databend-common-base = { workspace = true }
databend-common-exception = { workspace = true }

Expand Down
40 changes: 39 additions & 1 deletion src/common/column/src/types/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ use std::convert::TryFrom;
use std::ops::Neg;
use std::panic::RefUnwindSafe;

use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use bytemuck::Pod;
use bytemuck::Zeroable;
use databend_common_base::base::OrderedFloat;
use num_traits::NumCast;
use num_traits::ToPrimitive;
use serde_derive::Deserialize;
use serde_derive::Serialize;

use super::PrimitiveType;

Expand Down Expand Up @@ -243,11 +249,43 @@ impl NativeType for days_ms {
}

/// The in-memory representation of the MonthDayNano variant of the "Interval" logical type.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash, Zeroable, Pod)]
#[derive(
Debug,
Copy,
Clone,
Default,
PartialEq,
PartialOrd,
Ord,
Eq,
Hash,
Zeroable,
Pod,
Serialize,
Deserialize,
BorshSerialize,
BorshDeserialize,
)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct months_days_ns(pub i32, pub i32, pub i64);

impl NumCast for months_days_ns {
fn from<T: ToPrimitive>(n: T) -> Option<Self> {
n.to_i64().map(|n| Self::new(0, 0, n))
}
}

impl ToPrimitive for months_days_ns {
fn to_i64(&self) -> Option<i64> {
Some(self.2)
}

fn to_u64(&self) -> Option<u64> {
self.2.to_u64()
}
}

impl months_days_ns {
/// A new [`months_days_ns`].
#[inline]
Expand Down
Loading

0 comments on commit 0ecbfe1

Please sign in to comment.