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

perf: don't concat the batches when merging partitions #3410

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
18 changes: 11 additions & 7 deletions rust/lance/src/index/vector/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,20 @@ impl<S: IvfSubIndex + 'static, Q: Quantization + 'static> IvfIndexBuilder<S, Q>
)?
.try_collect::<Vec<_>>()
.await?;
let batch = arrow::compute::concat_batches(&batches[0].schema(), batches.iter())?;
let num_rows = batches.iter().map(|b| b.num_rows()).sum::<usize>();
if storage_writer.is_none() {
storage_writer = Some(FileWriter::try_new(
self.store.create(&storage_path).await?,
batch.schema_ref().as_ref().try_into()?,
batches[0].schema_ref().as_ref().try_into()?,
Default::default(),
)?);
}
storage_writer.as_mut().unwrap().write_batch(&batch).await?;
storage_ivf.add_partition(batch.num_rows() as u32);
storage_writer
.as_mut()
.unwrap()
.write_batches(batches.iter())
.await?;
storage_ivf.add_partition(num_rows as u32);
}

if index_size == 0 {
Expand All @@ -699,9 +703,9 @@ impl<S: IvfSubIndex + 'static, Q: Quantization + 'static> IvfIndexBuilder<S, Q>
)?
.try_collect::<Vec<_>>()
.await?;
let batch = arrow::compute::concat_batches(&batches[0].schema(), batches.iter())?;
index_writer.write_batch(&batch).await?;
index_ivf.add_partition(batch.num_rows() as u32);
let num_rows = batches.iter().map(|b| b.num_rows()).sum::<usize>();
index_writer.write_batches(batches.iter()).await?;
index_ivf.add_partition(num_rows as u32);
partition_index_metadata.push(
reader
.schema()
Expand Down
Loading