Skip to content

Commit

Permalink
fix: wrong cargo lock (apache#405)
Browse files Browse the repository at this point in the history
* chore: fix cargo.lock

* chore: move datafusion part to separate sub mod
  • Loading branch information
ShiKaiWi authored Nov 17, 2022
1 parent e85c84b commit 28f04a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

41 changes: 25 additions & 16 deletions common_types/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ use std::{
time::{self, Duration, SystemTime},
};

use datafusion::{
prelude::{col, lit, Expr},
scalar::ScalarValue,
};
use proto::common as common_pb;
use snafu::{Backtrace, OptionExt, Snafu};

Expand Down Expand Up @@ -280,18 +276,6 @@ impl TimeRange {
self.exclusive_end.min(other.exclusive_end),
)
}

/// Creates expression like:
/// start <= time && time < end
pub fn to_df_expr(&self, column_name: impl AsRef<str>) -> Expr {
let ts_start = ScalarValue::TimestampMillisecond(Some(self.inclusive_start.as_i64()), None);
let ts_end = ScalarValue::TimestampMillisecond(Some(self.exclusive_end.as_i64()), None);
let column_name = column_name.as_ref();
let ts_low = col(column_name).gt_eq(lit(ts_start));
let ts_high = col(column_name).lt(lit(ts_end));

ts_low.and(ts_high)
}
}

impl From<TimeRange> for common_pb::TimeRange {
Expand All @@ -314,6 +298,31 @@ impl TryFrom<common_pb::TimeRange> for TimeRange {
}
}

#[cfg(feature = "datafusion")]
mod datafusion_ext {
use datafusion::{
prelude::{col, lit, Expr},
scalar::ScalarValue,
};

use crate::time::TimeRange;

impl TimeRange {
/// Creates expression like:
/// start <= time && time < end
pub fn to_df_expr(&self, column_name: impl AsRef<str>) -> Expr {
let ts_start =
ScalarValue::TimestampMillisecond(Some(self.inclusive_start.as_i64()), None);
let ts_end = ScalarValue::TimestampMillisecond(Some(self.exclusive_end.as_i64()), None);
let column_name = column_name.as_ref();
let ts_low = col(column_name).gt_eq(lit(ts_start));
let ts_high = col(column_name).lt(lit(ts_end));

ts_low.and(ts_high)
}
}
}

#[cfg(test)]
mod test {
use std::time::Duration;
Expand Down

0 comments on commit 28f04a8

Please sign in to comment.