MCPcopy Create free account
hub / github.com/apache/datafusion / concat_and_sort_by_id

Function concat_and_sort_by_id

datafusion/datasource-json/src/source.rs:864–874  ·  view source on GitHub ↗

Concatenates `batches` and returns a single batch sorted ascending by the first (id) column.

(batches: &[RecordBatch])

Source from the content-addressed store, hash-verified

862 /// Concatenates `batches` and returns a single batch sorted ascending by
863 /// the first (id) column.
864 fn concat_and_sort_by_id(batches: &[RecordBatch]) -> Result<RecordBatch> {
865 let schema = test_schema();
866 let combined = compute::concat_batches(&schema, batches)?;
867 let indices = compute::sort_to_indices(combined.column(0), None, None)?;
868 let sorted_cols: Vec<_> = combined
869 .columns()
870 .iter()
871 .map(|col| compute::take(col.as_ref(), &indices, None))
872 .collect::<std::result::Result<_, _>>()?;
873 Ok(RecordBatch::try_new(schema, sorted_cols)?)
874 }
875
876 #[tokio::test]
877 async fn test_ndjson_partitioned() -> Result<()> {

Calls 6

columnMethod · 0.80
columnsMethod · 0.80
test_schemaFunction · 0.70
mapMethod · 0.45
iterMethod · 0.45
as_refMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…