-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Related * Part of #3741 ### Details Adds crate `re_arrow_util`. Adds two traits for downcasting `arrow` and `arrow2` arrays in such a way that we cannot accidentally cast one into another. This will be very important for the arrow migration. It also makes the code shorter.
- Loading branch information
Showing
48 changed files
with
320 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::TransportChunk; | ||
|
||
use arrow::datatypes::Schema as ArrowSchema; | ||
use arrow2::chunk::Chunk as Arrow2Chunk; | ||
|
||
/// Concatenate multiple [`TransportChunk`]s into one. | ||
/// | ||
/// This is a temporary method that we use while waiting to migrate towards `arrow-rs`. | ||
/// * `arrow2` doesn't have a `RecordBatch` type, therefore we emulate that using our `TransportChunk`s. | ||
/// * `arrow-rs` does have one, and it natively supports concatenation. | ||
pub fn concatenate_record_batches( | ||
schema: impl Into<ArrowSchema>, | ||
batches: &[TransportChunk], | ||
) -> anyhow::Result<TransportChunk> { | ||
let schema: ArrowSchema = schema.into(); | ||
anyhow::ensure!( | ||
batches | ||
.iter() | ||
.all(|batch| batch.schema_ref().as_ref() == &schema), | ||
"concatenate_record_batches: all batches must have the same schema" | ||
); | ||
|
||
let mut output_columns = Vec::new(); | ||
|
||
if !batches.is_empty() { | ||
for (i, _field) in schema.fields.iter().enumerate() { | ||
let arrays: Option<Vec<_>> = batches.iter().map(|batch| batch.column(i)).collect(); | ||
let arrays = arrays.ok_or_else(|| { | ||
anyhow::anyhow!("concatenate_record_batches: all batches must have the same schema") | ||
})?; | ||
let array = re_arrow_util::arrow2_util::concat_arrays(&arrays)?; | ||
output_columns.push(array); | ||
} | ||
} | ||
|
||
Ok(TransportChunk::new( | ||
schema, | ||
Arrow2Chunk::new(output_columns), | ||
)) | ||
} |
Oops, something went wrong.