Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cubejs-backend-native/Cargo.lock

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

27 changes: 25 additions & 2 deletions rust/cubenativeutils/Cargo.lock

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

51 changes: 47 additions & 4 deletions rust/cubesql/Cargo.lock

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

98 changes: 6 additions & 92 deletions rust/cubesql/cubesql/src/sql/dataframe.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
use chrono::{
format::{
Fixed, Item,
Numeric::{Day, Hour, Minute, Month, Second, Year},
Pad::Zero,
},
prelude::*,
};
use chrono_tz::Tz;
use chrono::prelude::*;
use comfy_table::{Cell, Table};
use datafusion::arrow::{
array::{
Expand All @@ -18,15 +10,10 @@ use datafusion::arrow::{
},
datatypes::{DataType, IntervalUnit, Schema, TimeUnit},
record_batch::RecordBatch,
temporal_conversions,
};
use pg_srv::IntervalValue;
use rust_decimal::prelude::*;
use serde::{Serialize, Serializer};
use std::{
fmt::{self, Debug, Formatter},
io,
};
use std::fmt::Debug;

use super::{ColumnFlags, ColumnType};
use crate::CubeError;
Expand Down Expand Up @@ -88,6 +75,10 @@ impl Row {
}
}

// Type aliases for compatibility - actual implementations are in pg-srv
pub type IntervalValue = pg_srv::IntervalValue;
pub type TimestampValue = pg_srv::TimestampValue;

#[derive(Debug)]
pub enum TableValue {
Null,
Expand Down Expand Up @@ -207,83 +198,6 @@ impl DataFrame {
}
}

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct TimestampValue {
unix_nano: i64,
tz: Option<String>,
}

impl TimestampValue {
pub fn new(mut unix_nano: i64, tz: Option<String>) -> TimestampValue {
// This is a hack to workaround a mismatch between on-disk and in-memory representations.
// We use millisecond precision on-disk.
unix_nano -= unix_nano % 1000;
TimestampValue { unix_nano, tz }
}

pub fn to_naive_datetime(&self) -> NaiveDateTime {
assert!(self.tz.is_none());

temporal_conversions::timestamp_ns_to_datetime(self.unix_nano)
}

pub fn to_fixed_datetime(&self) -> io::Result<DateTime<Tz>> {
assert!(self.tz.is_some());

let tz = self
.tz
.as_ref()
.unwrap()
.parse::<Tz>()
.map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?;

let ndt = temporal_conversions::timestamp_ns_to_datetime(self.unix_nano);
Ok(tz.from_utc_datetime(&ndt))
}

pub fn tz_ref(&self) -> &Option<String> {
&self.tz
}

pub fn get_time_stamp(&self) -> i64 {
self.unix_nano
}
}

impl Debug for TimestampValue {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("TimestampValue")
.field("unix_nano", &self.unix_nano)
.field("tz", &self.tz)
.field("str", &self.to_string())
.finish()
}
}

impl ToString for TimestampValue {
fn to_string(&self) -> String {
Utc.timestamp_nanos(self.unix_nano)
.format_with_items(
[
Item::Numeric(Year, Zero),
Item::Literal("-"),
Item::Numeric(Month, Zero),
Item::Literal("-"),
Item::Numeric(Day, Zero),
Item::Literal("T"),
Item::Numeric(Hour, Zero),
Item::Literal(":"),
Item::Numeric(Minute, Zero),
Item::Literal(":"),
Item::Numeric(Second, Zero),
Item::Fixed(Fixed::Nanosecond3),
]
.iter(),
)
.to_string()
}
}

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Decimal128Value {
n: i128,
Expand Down
Loading
Loading