|
21 | 21 | use std::sync::Arc;
|
22 | 22 |
|
23 | 23 | use crate::array::*;
|
24 |
| -use crate::compute::kernels::concat::concat; |
25 | 24 | use crate::datatypes::*;
|
26 | 25 | use crate::error::{ArrowError, Result};
|
27 | 26 |
|
@@ -390,32 +389,9 @@ impl RecordBatch {
|
390 | 389 | }
|
391 | 390 |
|
392 | 391 | /// Concatenates `batches` together into a single record batch.
|
| 392 | + #[deprecated(note = "please use arrow::compute::concat_batches")] |
393 | 393 | pub fn concat(schema: &SchemaRef, batches: &[Self]) -> Result<Self> {
|
394 |
| - if batches.is_empty() { |
395 |
| - return Ok(RecordBatch::new_empty(schema.clone())); |
396 |
| - } |
397 |
| - if let Some((i, _)) = batches |
398 |
| - .iter() |
399 |
| - .enumerate() |
400 |
| - .find(|&(_, batch)| batch.schema() != *schema) |
401 |
| - { |
402 |
| - return Err(ArrowError::InvalidArgumentError(format!( |
403 |
| - "batches[{}] schema is different with argument schema.", |
404 |
| - i |
405 |
| - ))); |
406 |
| - } |
407 |
| - let field_num = schema.fields().len(); |
408 |
| - let mut arrays = Vec::with_capacity(field_num); |
409 |
| - for i in 0..field_num { |
410 |
| - let array = concat( |
411 |
| - &batches |
412 |
| - .iter() |
413 |
| - .map(|batch| batch.column(i).as_ref()) |
414 |
| - .collect::<Vec<_>>(), |
415 |
| - )?; |
416 |
| - arrays.push(array); |
417 |
| - } |
418 |
| - Self::try_new(schema.clone(), arrays) |
| 394 | + crate::compute::concat_batches(schema, batches) |
419 | 395 | }
|
420 | 396 | }
|
421 | 397 |
|
@@ -713,78 +689,6 @@ mod tests {
|
713 | 689 | assert_eq!(batch.column(1).as_ref(), int.as_ref());
|
714 | 690 | }
|
715 | 691 |
|
716 |
| - #[test] |
717 |
| - fn concat_record_batches() { |
718 |
| - let schema = Arc::new(Schema::new(vec![ |
719 |
| - Field::new("a", DataType::Int32, false), |
720 |
| - Field::new("b", DataType::Utf8, false), |
721 |
| - ])); |
722 |
| - let batch1 = RecordBatch::try_new( |
723 |
| - schema.clone(), |
724 |
| - vec![ |
725 |
| - Arc::new(Int32Array::from(vec![1, 2])), |
726 |
| - Arc::new(StringArray::from(vec!["a", "b"])), |
727 |
| - ], |
728 |
| - ) |
729 |
| - .unwrap(); |
730 |
| - let batch2 = RecordBatch::try_new( |
731 |
| - schema.clone(), |
732 |
| - vec![ |
733 |
| - Arc::new(Int32Array::from(vec![3, 4])), |
734 |
| - Arc::new(StringArray::from(vec!["c", "d"])), |
735 |
| - ], |
736 |
| - ) |
737 |
| - .unwrap(); |
738 |
| - let new_batch = RecordBatch::concat(&schema, &[batch1, batch2]).unwrap(); |
739 |
| - assert_eq!(new_batch.schema().as_ref(), schema.as_ref()); |
740 |
| - assert_eq!(2, new_batch.num_columns()); |
741 |
| - assert_eq!(4, new_batch.num_rows()); |
742 |
| - } |
743 |
| - |
744 |
| - #[test] |
745 |
| - fn concat_empty_record_batch() { |
746 |
| - let schema = Arc::new(Schema::new(vec![ |
747 |
| - Field::new("a", DataType::Int32, false), |
748 |
| - Field::new("b", DataType::Utf8, false), |
749 |
| - ])); |
750 |
| - let batch = RecordBatch::concat(&schema, &[]).unwrap(); |
751 |
| - assert_eq!(batch.schema().as_ref(), schema.as_ref()); |
752 |
| - assert_eq!(0, batch.num_rows()); |
753 |
| - } |
754 |
| - |
755 |
| - #[test] |
756 |
| - fn concat_record_batches_of_different_schemas() { |
757 |
| - let schema1 = Arc::new(Schema::new(vec![ |
758 |
| - Field::new("a", DataType::Int32, false), |
759 |
| - Field::new("b", DataType::Utf8, false), |
760 |
| - ])); |
761 |
| - let schema2 = Arc::new(Schema::new(vec![ |
762 |
| - Field::new("c", DataType::Int32, false), |
763 |
| - Field::new("d", DataType::Utf8, false), |
764 |
| - ])); |
765 |
| - let batch1 = RecordBatch::try_new( |
766 |
| - schema1.clone(), |
767 |
| - vec![ |
768 |
| - Arc::new(Int32Array::from(vec![1, 2])), |
769 |
| - Arc::new(StringArray::from(vec!["a", "b"])), |
770 |
| - ], |
771 |
| - ) |
772 |
| - .unwrap(); |
773 |
| - let batch2 = RecordBatch::try_new( |
774 |
| - schema2, |
775 |
| - vec![ |
776 |
| - Arc::new(Int32Array::from(vec![3, 4])), |
777 |
| - Arc::new(StringArray::from(vec!["c", "d"])), |
778 |
| - ], |
779 |
| - ) |
780 |
| - .unwrap(); |
781 |
| - let error = RecordBatch::concat(&schema1, &[batch1, batch2]).unwrap_err(); |
782 |
| - assert_eq!( |
783 |
| - error.to_string(), |
784 |
| - "Invalid argument error: batches[1] schema is different with argument schema.", |
785 |
| - ); |
786 |
| - } |
787 |
| - |
788 | 692 | #[test]
|
789 | 693 | fn record_batch_equality() {
|
790 | 694 | let id_arr1 = Int32Array::from(vec![1, 2, 3, 4]);
|
|
0 commit comments