fix: Return Partition rather than strings
parent
cd66814c3d
commit
1b36d6b0cd
|
@ -135,8 +135,8 @@ message ListPartitionsRequest {
|
|||
}
|
||||
|
||||
message ListPartitionsResponse {
|
||||
// All partition keys in a database
|
||||
repeated string partition_keys = 1;
|
||||
// All partitions in a database
|
||||
repeated Partition partitions = 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -303,11 +303,11 @@ impl Client {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// List partition keys of a database
|
||||
/// List all partitions of the database
|
||||
pub async fn list_partitions(
|
||||
&mut self,
|
||||
db_name: impl Into<String>,
|
||||
) -> Result<Vec<String>, ListPartitionsError> {
|
||||
) -> Result<Vec<Partition>, ListPartitionsError> {
|
||||
let db_name = db_name.into();
|
||||
let response = self
|
||||
.inner
|
||||
|
@ -318,12 +318,12 @@ impl Client {
|
|||
_ => ListPartitionsError::ServerError(status),
|
||||
})?;
|
||||
|
||||
let ListPartitionsResponse { partition_keys } = response.into_inner();
|
||||
let ListPartitionsResponse { partitions } = response.into_inner();
|
||||
|
||||
Ok(partition_keys)
|
||||
Ok(partitions)
|
||||
}
|
||||
|
||||
/// Get details about a partition
|
||||
/// Get details about a specific partition
|
||||
pub async fn get_partition(
|
||||
&mut self,
|
||||
db_name: impl Into<String>,
|
||||
|
|
|
@ -65,7 +65,9 @@ pub async fn command(url: String, config: Config) -> Result<()> {
|
|||
match config.command {
|
||||
Command::List(list) => {
|
||||
let List { db_name } = list;
|
||||
let partition_keys = client.list_partitions(db_name).await?;
|
||||
let partitions = client.list_partitions(db_name).await?;
|
||||
let partition_keys = partitions.into_iter().map(|p| p.key).collect::<Vec<_>>();
|
||||
|
||||
serde_json::to_writer_pretty(std::io::stdout(), &partition_keys)?;
|
||||
}
|
||||
Command::Get(get) => {
|
||||
|
|
|
@ -198,8 +198,12 @@ where
|
|||
})?;
|
||||
|
||||
let partition_keys = db.partition_keys().map_err(default_db_error_handler)?;
|
||||
let partitions = partition_keys
|
||||
.into_iter()
|
||||
.map(|key| Partition { key })
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(Response::new(ListPartitionsResponse { partition_keys }))
|
||||
Ok(Response::new(ListPartitionsResponse { partitions }))
|
||||
}
|
||||
|
||||
async fn get_partition(
|
||||
|
|
|
@ -304,9 +304,16 @@ async fn test_partition_list() {
|
|||
.expect("listing partition");
|
||||
|
||||
// ensure the output order is consistent
|
||||
partitions.sort();
|
||||
partitions.sort_by(|p1, p2| p1.key.cmp(&p2.key));
|
||||
|
||||
let expected = vec!["cpu".to_string(), "mem".to_string()];
|
||||
let expected = vec![
|
||||
Partition {
|
||||
key: "cpu".to_string(),
|
||||
},
|
||||
Partition {
|
||||
key: "mem".to_string(),
|
||||
},
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
expected, partitions,
|
||||
|
|
Loading…
Reference in New Issue