Skip to content

Commit

Permalink
merge cmc/datastore/get_a_single_row (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Dec 18, 2022
1 parent 1b3a05e commit b7f3549
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
6 changes: 2 additions & 4 deletions crates/re_arrow_store/benches/data_store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use arrow2::array::{Array, ListArray, StructArray};
use arrow2::array::{Array, StructArray};
use criterion::{criterion_group, criterion_main, Criterion};

use re_arrow_store::{DataStore, TimeQuery, TimelineQuery};
Expand Down Expand Up @@ -89,9 +89,7 @@ fn query_messages(store: &mut DataStore) -> Box<dyn Array> {
let mut results = store.get(&[component], &row_indices);

let row = std::mem::take(&mut results[0]).unwrap();
let list = row.as_any().downcast_ref::<ListArray<i32>>().unwrap();
let rects = list.value(0);
let rects = rects.as_any().downcast_ref::<StructArray>().unwrap();
let rects = row.as_any().downcast_ref::<StructArray>().unwrap();
assert_eq!(NUM_RECTS as usize, rects.len());

row
Expand Down
14 changes: 9 additions & 5 deletions crates/re_arrow_store/src/store_read.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::atomic::Ordering;

use arrow2::{
array::{Array, Int64Array, MutableArray, UInt64Array, UInt64Vec},
array::{Array, Int64Array, ListArray, MutableArray, UInt64Array, UInt64Vec},
datatypes::{DataType, TimeUnit},
};

Expand Down Expand Up @@ -110,8 +110,7 @@ impl DataStore {
/// .map(|(&component, col)| Series::try_from((component, col)).unwrap())
/// .collect();
///
/// let df = DataFrame::new(series).unwrap();
/// df.explode(df.get_column_names()).unwrap()
/// DataFrame::new(series).unwrap()
/// };
///
/// df
Expand Down Expand Up @@ -581,10 +580,15 @@ impl ComponentBucket {
&self.name
}

// Panics on out-of-bounds
/// Returns a shallow clone of the row data for the given `row_idx`.
pub fn get(&self, row_idx: RowIndex) -> Box<dyn Array> {
let row_idx = row_idx.as_u64() - self.row_offset.as_u64();
self.data.slice(row_idx as usize, 1)
let rows = self.data.slice(row_idx as usize, 1);
// This has to be safe to unwrap, otherwise it would never have made it past insertion.
rows.as_any()
.downcast_ref::<ListArray<i32>>()
.unwrap()
.value(0)
}

/// Returns the entire data Array in this component
Expand Down
6 changes: 2 additions & 4 deletions crates/re_arrow_store/tests/data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,7 @@ impl DataTracker {
})
.collect::<Vec<_>>();

let df = DataFrame::new(series).unwrap();
df.explode(df.get_column_names()).unwrap()
DataFrame::new(series).unwrap()
};

let series = expected
Expand Down Expand Up @@ -797,8 +796,7 @@ impl DataTracker {
.map(|(&component, col)| Series::try_from((component, col)).unwrap())
.collect();

let df = DataFrame::new(series).unwrap();
df.explode(df.get_column_names()).unwrap()
DataFrame::new(series).unwrap()
};

df
Expand Down
5 changes: 1 addition & 4 deletions crates/re_query/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ pub fn get_component_with_instances(
.map(|(&component, col)| Series::try_from((component, col)))
.collect();

let df = DataFrame::new(series?)?;
let exploded = df.explode(df.get_column_names())?;

Ok(exploded)
DataFrame::new(series?).map_err(Into::into)
}

/// If a `DataFrame` has no `Instance` column create one from the row numbers
Expand Down

0 comments on commit b7f3549

Please sign in to comment.