Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct BatchType in re_sorbet #9052

Merged
merged 3 commits into from
Feb 17, 2025
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
6 changes: 5 additions & 1 deletion crates/store/re_sorbet/src/chunk_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl ChunkBatch {
data_arrays: Vec<ArrowArrayRef>,
) -> Result<Self, SorbetError> {
Self::try_from(SorbetBatch::try_new(
crate::BatchType::Chunk,
schema.into(),
Some(row_ids),
index_arrays,
Expand Down Expand Up @@ -131,7 +132,10 @@ impl TryFrom<&ArrowRecordBatch> for ChunkBatch {
fn try_from(batch: &ArrowRecordBatch) -> Result<Self, Self::Error> {
re_tracing::profile_function!();

Self::try_from(SorbetBatch::try_from(batch)?)
Self::try_from(SorbetBatch::try_from_record_batch(
batch,
crate::BatchType::Chunk,
)?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/store/re_sorbet/src/chunk_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl ChunkSchema {
}

pub fn arrow_fields(&self) -> Vec<ArrowField> {
self.sorbet.columns.arrow_fields()
self.sorbet.columns.arrow_fields(crate::BatchType::Chunk)
}
}

Expand Down
19 changes: 11 additions & 8 deletions crates/store/re_sorbet/src/sorbet_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct SorbetBatch {

impl SorbetBatch {
pub fn try_new(
batch_type: crate::BatchType,
schema: SorbetSchema,
row_ids: Option<ArrowArrayRef>,
index_arrays: Vec<ArrowArrayRef>,
Expand All @@ -33,7 +34,7 @@ impl SorbetBatch {
let arrow_columns = itertools::chain!(row_ids, index_arrays, data_arrays).collect();

let batch = ArrowRecordBatch::try_new(
std::sync::Arc::new(ArrowSchema::from(&schema)),
std::sync::Arc::new(schema.to_arrow(batch_type)),
arrow_columns,
)?;

Expand Down Expand Up @@ -143,20 +144,22 @@ impl From<&SorbetBatch> for ArrowRecordBatch {
}
}

impl TryFrom<&ArrowRecordBatch> for SorbetBatch {
type Error = SorbetError;

impl SorbetBatch {
/// Will automatically wrap data columns in `ListArrays` if they are not already.
fn try_from(batch: &ArrowRecordBatch) -> Result<Self, Self::Error> {
pub fn try_from_record_batch(
batch: &ArrowRecordBatch,
batch_type: crate::BatchType,
) -> Result<Self, SorbetError> {
re_tracing::profile_function!();

let batch = make_all_data_columns_list_arrays(batch);

let sorbet_schema = SorbetSchema::try_from(batch.schema_ref().as_ref())?;

for (field, column) in
itertools::izip!(sorbet_schema.columns.arrow_fields(), batch.columns())
{
for (field, column) in itertools::izip!(
sorbet_schema.columns.arrow_fields(batch_type),
batch.columns()
) {
debug_assert_eq!(field.data_type(), column.data_type());
}

Expand Down
4 changes: 2 additions & 2 deletions crates/store/re_sorbet/src/sorbet_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl SorbetColumnDescriptors {
}
}

pub fn arrow_fields(&self) -> Vec<ArrowField> {
pub fn arrow_fields(&self, batch_type: crate::BatchType) -> Vec<ArrowField> {
let Self {
row_id,
indices,
Expand All @@ -110,7 +110,7 @@ impl SorbetColumnDescriptors {
fields.extend(
components
.iter()
.map(|column| column.to_arrow_field(crate::BatchType::Chunk)),
.map(|column| column.to_arrow_field(batch_type)),
);
fields
}
Expand Down
10 changes: 5 additions & 5 deletions crates/store/re_sorbet/src/sorbet_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ impl From<SorbetSchema> for SorbetColumnDescriptors {
}
}

impl From<&SorbetSchema> for ArrowSchema {
fn from(sorbet_schema: &SorbetSchema) -> Self {
Self {
metadata: sorbet_schema.arrow_batch_metadata(),
fields: sorbet_schema.columns.arrow_fields().into(),
impl SorbetSchema {
pub fn to_arrow(&self, batch_type: crate::BatchType) -> ArrowSchema {
ArrowSchema {
metadata: self.arrow_batch_metadata(),
fields: self.columns.arrow_fields(batch_type).into(),
}
}
}
Expand Down
Loading