fn sort_batch(record_batch: RecordBatch, schema: Schema) -> (RecordBatch, SortKey) {
    // build dummy sort key
    let mut sort_key_builder = SortKeyBuilder::new();
    for field in schema.tags_iter() {
        sort_key_builder = sort_key_builder.with_col(field.name().clone());
    }
    for field in schema.time_iter() {
        sort_key_builder = sort_key_builder.with_col(field.name().clone());
    }
    let sort_key = sort_key_builder.build();

    // set up sorting
    let mut sort_columns = Vec::with_capacity(record_batch.num_columns());
    let mut reverse_index: Vec<_> = (0..record_batch.num_columns()).map(|_| None).collect();
    for (column_name, _options) in sort_key.iter() {
        let index = record_batch
            .schema()
            .column_with_name(column_name.as_ref())
            .unwrap()
            .0;
        reverse_index[index] = Some(sort_columns.len());
        sort_columns.push(SortColumn {
            values: Arc::clone(record_batch.column(index)),
            options: Some(SortOptions::default()),
        });
    }
    for (index, reverse_index) in reverse_index.iter_mut().enumerate() {
        if reverse_index.is_none() {
            *reverse_index = Some(sort_columns.len());
            sort_columns.push(SortColumn {
                values: Arc::clone(record_batch.column(index)),
                options: None,
            });
        }
    }

    // execute sorting
    let arrays = lexsort(&sort_columns, None).unwrap();

    // re-create record batch
    let arrays: Vec<_> = reverse_index
        .into_iter()
        .map(|index| {
            let index = index.unwrap();
            Arc::clone(&arrays[index])
        })
        .collect();
    let record_batch = RecordBatch::try_new(record_batch.schema(), arrays).unwrap();

    (record_batch, sort_key)
}
/// Sort arrow record batch into arrow record batch and sort key.
Sort arrow record batch into arrow record batch and sort key.
Sort arrow record batch into arrow record batch and sort key .
fn sort_batch(record_batch: RecordBatch, schema: Schema) -> (RecordBatch, SortKey) {
    // build dummy sort key
    let mut sort_key_builder = SortKeyBuilder::new();
    for field in schema.tags_iter() {
        sort_key_builder = sort_key_builder.with_col(field.name().clone());
    }
    for field in schema.time_iter() {
        sort_key_builder = sort_key_builder.with_col(field.name().clone());
    }
    let sort_key = sort_key_builder.build();
    // set up sorting
    let mut sort_columns = Vec::with_capacity(record_batch.num_columns());
    let mut reverse_index: Vec<_> = (0..record_batch.num_columns()).map(|_| None).collect();
    for (column_name, _options) in sort_key.iter() {
        let index = record_batch
            .schema()
            .column_with_name(column_name.as_ref())
            .unwrap()
            .0;
        reverse_index[index] = Some(sort_columns.len());
        sort_columns.push(SortColumn {
            values: Arc::clone(record_batch.column(index)),
            options: Some(SortOptions::default()),
        });
    }
    for (index, reverse_index) in reverse_index.iter_mut().enumerate() {
        if reverse_index.is_none() {
            *reverse_index = Some(sort_columns.len());
            sort_columns.push(SortColumn {
                values: Arc::clone(record_batch.column(index)),
                options: None,
            });
        }
    }
    // execute sorting
    let arrays = lexsort(&sort_columns, None).unwrap();
    // re-create record batch
    let arrays: Vec<_> = reverse_index
        .into_iter()
        .map(|index| {
            let index = index.unwrap();
            Arc::clone(&arrays[index])
        })
        .collect();
    let record_batch = RecordBatch::try_new(record_batch.schema(), arrays).unwrap();
    (record_batch, sort_key)
}
fn sort_batch ( record_batch : RecordBatch , schema : Schema ) -> ( RecordBatch , SortKey ) { // build dummy sort key let mut sort_key_builder = SortKeyBuilder :: new ( ) ; for field in schema . tags_iter ( ) { sort_key_builder = sort_key_builder . with_col ( field . name ( ) . clone ( ) ) ; } for field in schema . time_iter ( ) { sort_key_builder = sort_key_builder . with_col ( field . name ( ) . clone ( ) ) ; } let sort_key = sort_key_builder . build ( ) ; // set up sorting let mut sort_columns = Vec :: with_capacity ( record_batch . num_columns ( ) ) ; let mut reverse_index : Vec < _ > = ( 0 .. record_batch . num_columns ( ) ) . map ( | _ | None ) . collect ( ) ; for ( column_name , _options ) in sort_key . iter ( ) { let index = record_batch . schema ( ) . column_with_name ( column_name . as_ref ( ) ) . unwrap ( ) . 0 ; reverse_index [ index ] = Some ( sort_columns . len ( ) ) ; sort_columns . push ( SortColumn { values : Arc :: clone ( record_batch . column ( index ) ) , options : Some ( SortOptions :: default ( ) ) , } ) ; } for ( index , reverse_index ) in reverse_index . iter_mut ( ) . enumerate ( ) { if reverse_index . is_none ( ) { * reverse_index = Some ( sort_columns . len ( ) ) ; sort_columns . push ( SortColumn { values : Arc :: clone ( record_batch . column ( index ) ) , options : None , } ) ; } } // execute sorting let arrays = lexsort ( & sort_columns , None ) . unwrap ( ) ; // re-create record batch let arrays : Vec < _ > = reverse_index . into_iter ( ) . map ( | index | { let index = index . unwrap ( ) ; Arc :: clone ( & arrays [ index ] ) } ) . collect ( ) ; let record_batch = RecordBatch :: try_new ( record_batch . schema ( ) , arrays ) . unwrap ( ) ; ( record_batch , sort_key ) }
Sort arrow record batch into arrow record batch and sort key.
Sort arrow record batch into arrow record batch and sort key .
record_batch
RecordBatch
schema
Schema
record_batch
RecordBatch
schema
Schema