Skip to content

Commit aad04d5

Browse files
authored
Data Explorer: Implement sort-columns-by-type feature (#893)
Incorporates new data explorer comm changes
1 parent dd48d20 commit aad04d5

File tree

3 files changed

+364
-40
lines changed

3 files changed

+364
-40
lines changed

crates/amalthea/src/comm/data_explorer_comm.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub struct OpenDatasetResult {
2121
/// Result in Methods
2222
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
2323
pub struct SearchSchemaResult {
24-
/// The column indices of the matching column indices in the indicated
25-
/// sort order
24+
/// The column indices that match the search parameters in the indicated
25+
/// sort order.
2626
pub matches: Vec<i64>
2727
}
2828

@@ -696,13 +696,21 @@ pub enum SearchSchemaSortOrder {
696696
#[strum(to_string = "original")]
697697
Original,
698698

699-
#[serde(rename = "ascending")]
700-
#[strum(to_string = "ascending")]
701-
Ascending,
699+
#[serde(rename = "ascending_name")]
700+
#[strum(to_string = "ascending_name")]
701+
AscendingName,
702702

703-
#[serde(rename = "descending")]
704-
#[strum(to_string = "descending")]
705-
Descending
703+
#[serde(rename = "descending_name")]
704+
#[strum(to_string = "descending_name")]
705+
DescendingName,
706+
707+
#[serde(rename = "ascending_type")]
708+
#[strum(to_string = "ascending_type")]
709+
AscendingType,
710+
711+
#[serde(rename = "descending_type")]
712+
#[strum(to_string = "descending_type")]
713+
DescendingType
706714
}
707715

708716
/// Possible values for ColumnDisplayType

crates/ark/src/data_explorer/r_data_explorer.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ use amalthea::comm::data_explorer_comm::RowFilterParams;
4444
use amalthea::comm::data_explorer_comm::RowFilterType;
4545
use amalthea::comm::data_explorer_comm::RowFilterTypeSupportStatus;
4646
use amalthea::comm::data_explorer_comm::SearchSchemaFeatures;
47+
use amalthea::comm::data_explorer_comm::SearchSchemaParams;
48+
use amalthea::comm::data_explorer_comm::SearchSchemaResult;
49+
use amalthea::comm::data_explorer_comm::SearchSchemaSortOrder;
4750
use amalthea::comm::data_explorer_comm::SetColumnFiltersFeatures;
4851
use amalthea::comm::data_explorer_comm::SetRowFiltersFeatures;
4952
use amalthea::comm::data_explorer_comm::SetRowFiltersParams;
@@ -866,7 +869,7 @@ impl RDataExplorer {
866869
/// - `params`: The search parameters including filters and sort order.
867870
fn search_schema(
868871
&self,
869-
params: amalthea::comm::data_explorer_comm::SearchSchemaParams,
872+
params: SearchSchemaParams,
870873
) -> anyhow::Result<DataExplorerBackendReply> {
871874
let all_columns = &self.shape.columns;
872875

@@ -893,25 +896,43 @@ impl RDataExplorer {
893896

894897
// Apply sort order
895898
match params.sort_order {
896-
amalthea::comm::data_explorer_comm::SearchSchemaSortOrder::Original => {
899+
SearchSchemaSortOrder::Original => {
897900
// matching_indices is already in original order
898901
},
899-
order => {
900-
let ascending = matches!(
901-
order,
902-
amalthea::comm::data_explorer_comm::SearchSchemaSortOrder::Ascending
903-
);
902+
SearchSchemaSortOrder::AscendingName => {
904903
matching_indices.sort_by(|&a, &b| {
905-
let ord = all_columns[a as usize]
904+
all_columns[a as usize]
906905
.column_name
907-
.cmp(&all_columns[b as usize].column_name);
908-
if ascending { ord } else { ord.reverse() }
906+
.cmp(&all_columns[b as usize].column_name)
909907
});
910-
}
908+
},
909+
SearchSchemaSortOrder::DescendingName => {
910+
matching_indices.sort_by(|&a, &b| {
911+
all_columns[b as usize]
912+
.column_name
913+
.cmp(&all_columns[a as usize].column_name)
914+
});
915+
},
916+
SearchSchemaSortOrder::AscendingType => {
917+
matching_indices.sort_by(|&a, &b| {
918+
all_columns[a as usize]
919+
.type_name
920+
.to_lowercase()
921+
.cmp(&all_columns[b as usize].type_name.to_lowercase())
922+
});
923+
},
924+
SearchSchemaSortOrder::DescendingType => {
925+
matching_indices.sort_by(|&a, &b| {
926+
all_columns[b as usize]
927+
.type_name
928+
.to_lowercase()
929+
.cmp(&all_columns[a as usize].type_name.to_lowercase())
930+
});
931+
},
911932
}
912933

913934
Ok(DataExplorerBackendReply::SearchSchemaReply(
914-
amalthea::comm::data_explorer_comm::SearchSchemaResult {
935+
SearchSchemaResult {
915936
matches: matching_indices,
916937
},
917938
))

0 commit comments

Comments
 (0)