refactor: return row id

pull/24376/head
Edd Robinson 2020-08-06 14:43:02 +01:00
parent 150a5a9c81
commit ee8ac1b909
2 changed files with 10 additions and 10 deletions

View File

@ -56,7 +56,7 @@ fn main() {
// println!("{:?}", segments.last("host")); // println!("{:?}", segments.last("host"));
// println!("{:?}", segments.segments().last().unwrap().row(14899)); // println!("{:?}", segments.segments().last().unwrap().row(14899));
time_row_by_id(&store, 14899); time_row_by_last_ts(&store);
} }
fn build_store( fn build_store(
@ -214,13 +214,15 @@ fn time_column_first(store: &Store) {
); );
} }
fn time_row_by_id(store: &Store, row_id: usize) { fn time_row_by_last_ts(store: &Store) {
let repeat = 100000; let repeat = 100000;
let mut total_time: std::time::Duration = std::time::Duration::new(0, 0); let mut total_time: std::time::Duration = std::time::Duration::new(0, 0);
let mut total_max = 0; let mut total_max = 0;
for _ in 1..repeat { let segments = store.segments();
for _ in 0..repeat {
let now = std::time::Instant::now(); let now = std::time::Instant::now();
let segments = store.segments();
let (_, _, row_id) = segments.last("time").unwrap();
let res = segments.segments().last().unwrap().row(row_id).unwrap(); let res = segments.segments().last().unwrap().row(row_id).unwrap();
total_time += now.elapsed(); total_time += now.elapsed();
total_max += res.len(); total_max += res.len();

View File

@ -234,7 +234,7 @@ impl<'a> Segments<'a> {
/// If the time column has multiple max time values then the result is abitrary. /// If the time column has multiple max time values then the result is abitrary.
/// ///
/// TODO(edd): could return NULL value.. /// TODO(edd): could return NULL value..
pub fn first(&self, column_name: &str) -> Option<(i64, Option<column::Scalar>)> { pub fn first(&self, column_name: &str) -> Option<(i64, Option<column::Scalar>, usize)> {
// First let's find the segment with the latest time range. // First let's find the segment with the latest time range.
// notice we order a < b on max time range. // notice we order a < b on max time range.
let segment = self let segment = self
@ -250,10 +250,9 @@ impl<'a> Segments<'a> {
let min_ts_id = ts_col.row_id_eq_value(min_ts).unwrap(); let min_ts_id = ts_col.row_id_eq_value(min_ts).unwrap();
println!("first ts is {:?} at row {:?}", min_ts, min_ts_id);
// now we have row id we can get value for that row id // now we have row id we can get value for that row id
let value = segment.column(column_name).unwrap().value(min_ts_id); let value = segment.column(column_name).unwrap().value(min_ts_id);
Some((min_ts, value)) Some((min_ts, value, min_ts_id))
} else { } else {
panic!("time column wrong type!"); panic!("time column wrong type!");
} }
@ -267,7 +266,7 @@ impl<'a> Segments<'a> {
/// If the time column has multiple max time values then the result is abitrary. /// If the time column has multiple max time values then the result is abitrary.
/// ///
/// TODO(edd): could return NULL value.. /// TODO(edd): could return NULL value..
pub fn last(&self, column_name: &str) -> Option<(i64, Option<column::Scalar>)> { pub fn last(&self, column_name: &str) -> Option<(i64, Option<column::Scalar>, usize)> {
// First let's find the segment with the latest time range. // First let's find the segment with the latest time range.
// notice we order a > b on max time range. // notice we order a > b on max time range.
let segment = self let segment = self
@ -283,10 +282,9 @@ impl<'a> Segments<'a> {
let max_ts_id = ts_col.row_id_eq_value(max_ts).unwrap(); let max_ts_id = ts_col.row_id_eq_value(max_ts).unwrap();
println!("last ts is {:?} at row {:?}", max_ts, max_ts_id);
// now we have row id we can get value for that row id // now we have row id we can get value for that row id
let value = segment.column(column_name).unwrap().value(max_ts_id); let value = segment.column(column_name).unwrap().value(max_ts_id);
Some((max_ts, value)) Some((max_ts, value, max_ts_id))
} else { } else {
panic!("time column wrong type!"); panic!("time column wrong type!");
} }