pub fn adjust_sort_key_columns(
    catalog_sort_key: &SortKey,
    primary_key: &[&str],
) -> (SortKey, Option<SortKey>) {
    let existing_columns_without_time = catalog_sort_key
        .iter()
        .map(|(col, _opts)| col)
        .cloned()
        .filter(|col| TIME_COLUMN_NAME != col.as_ref());
    let new_columns: Vec<_> = primary_key
        .iter()
        .filter(|col| !catalog_sort_key.contains(col))
        .collect();

    let metadata_sort_key = SortKey::from_columns(
        existing_columns_without_time
            .clone()
            .filter(|col| primary_key.contains(&col.as_ref()))
            .chain(new_columns.iter().map(|&&col| Arc::from(col)))
            .chain(std::iter::once(Arc::from(TIME_COLUMN_NAME))),
    );

    let catalog_update = if new_columns.is_empty() {
        None
    } else {
        Some(SortKey::from_columns(
            existing_columns_without_time
                .chain(new_columns.into_iter().map(|&col| Arc::from(col)))
                .chain(std::iter::once(Arc::from(TIME_COLUMN_NAME))),
        ))
    };

    (metadata_sort_key, catalog_update)
}
/// Given a sort key from the catalog and the primary key (tags + time) from the data, return the
/// sort key that should be used for this parquet file and, if needed, the sort key that should
/// be updated in the catalog. These are computed as follows:
///
/// - Columns that appear in both the primary key and the catalog sort key should appear in the
///   same order as they appear in the catalog sort key.
/// - If there are new columns that appear in the primary key, add the new columns to the end of
///   the catalog sort key's tag list. Also return an updated catalog sort key to save the new
///   column in the catalog.
/// - If there are columns that appear in the catalog sort key but aren't present in this data's
///   primary key, don't include them in the sort key to be used for this data. Don't remove them
///   from the catalog sort key.
Given a sort key from the catalog and the primary key (tags + time) from the data, return the
sort key that should be used for this parquet file and, if needed, the sort key that should
be updated in the catalog. These are computed as follows.

Columns that appear in both the primary key and the catalog sort key should appear in the
same order as they appear in the catalog sort key.
If there are new columns that appear in the primary key, add the new columns to the end of
the catalog sort key's tag list. Also return an updated catalog sort key to save the new
column in the catalog.
If there are columns that appear in the catalog sort key but aren't present in this data's
primary key, don't include them in the sort key to be used for this data. Don't remove them
from the catalog sort key.
Given a sort key from the catalog and the primary key ( tags + time ) from the data return the sort key that should be used for this parquet file and if needed the sort key that should be updated in the catalog . These are computed as follows . Columns that appear in both the primary key and the catalog sort key should appear in the same order as they appear in the catalog sort key . If there are new columns that appear in the primary key add the new columns to the end of the catalog sort key ' s tag list . Also return an updated catalog sort key to save the new column in the catalog . If there are columns that appear in the catalog sort key but aren ' t present in this data ' s primary key don ' t include them in the sort key to be used for this data . Don ' t remove them from the catalog sort key .
pub fn adjust_sort_key_columns(
    catalog_sort_key: &SortKey,
    primary_key: &[&str],
) -> (SortKey, Option<SortKey>) {
    let existing_columns_without_time = catalog_sort_key
        .iter()
        .map(|(col, _opts)| col)
        .cloned()
        .filter(|col| TIME_COLUMN_NAME != col.as_ref());
    let new_columns: Vec<_> = primary_key
        .iter()
        .filter(|col| !catalog_sort_key.contains(col))
        .collect();
    let metadata_sort_key = SortKey::from_columns(
        existing_columns_without_time
            .clone()
            .filter(|col| primary_key.contains(&col.as_ref()))
            .chain(new_columns.iter().map(|&&col| Arc::from(col)))
            .chain(std::iter::once(Arc::from(TIME_COLUMN_NAME))),
    );
    let catalog_update = if new_columns.is_empty() {
        None
    } else {
        Some(SortKey::from_columns(
            existing_columns_without_time
                .chain(new_columns.into_iter().map(|&col| Arc::from(col)))
                .chain(std::iter::once(Arc::from(TIME_COLUMN_NAME))),
        ))
    };
    (metadata_sort_key, catalog_update)
}
pub fn adjust_sort_key_columns ( catalog_sort_key : & SortKey , primary_key : & [ & str ] , ) -> ( SortKey , Option < SortKey > ) { let existing_columns_without_time = catalog_sort_key . iter ( ) . map ( | ( col , _opts ) | col ) . cloned ( ) . filter ( | col | TIME_COLUMN_NAME != col . as_ref ( ) ) ; let new_columns : Vec < _ > = primary_key . iter ( ) . filter ( | col | ! catalog_sort_key . contains ( col ) ) . collect ( ) ; let metadata_sort_key = SortKey :: from_columns ( existing_columns_without_time . clone ( ) . filter ( | col | primary_key . contains ( & col . as_ref ( ) ) ) . chain ( new_columns . iter ( ) . map ( | & & col | Arc :: from ( col ) ) ) . chain ( std :: iter :: once ( Arc :: from ( TIME_COLUMN_NAME ) ) ) , ) ; let catalog_update = if new_columns . is_empty ( ) { None } else { Some ( SortKey :: from_columns ( existing_columns_without_time . chain ( new_columns . into_iter ( ) . map ( | & col | Arc :: from ( col ) ) ) . chain ( std :: iter :: once ( Arc :: from ( TIME_COLUMN_NAME ) ) ) , ) ) } ; ( metadata_sort_key , catalog_update ) }
Given a sort key from the catalog and the primary key (tags + time) from the data, return the
sort key that should be used for this parquet file and, if needed, the sort key that should
be updated in the catalog.
Given a sort key from the catalog and the primary key ( tags + time ) from the data return the sort key that should be used for this parquet file and if needed the sort key that should be updated in the catalog .
catalog_sort_key
&SortKey
primary_key
&[&str]
catalog_sort_key
&SortKey
primary_key
&[&str]