Skip to content

Commit

Permalink
fix: make GetCatalogsBuilder sort catalog names (#6864)
Browse files Browse the repository at this point in the history
* fix: sort catalog names

* apply code suggestion from tustvold

Co-authored-by: Raphael Taylor-Davies <[email protected]>

---------

Co-authored-by: Raphael Taylor-Davies <[email protected]>
  • Loading branch information
niebayes and tustvold authored Dec 13, 2024
1 parent eb7ab83 commit c4dbf0d
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion arrow-flight/src/sql/metadata/catalogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ impl GetCatalogsBuilder {
/// builds a `RecordBatch` with the correct schema for a
/// [`CommandGetCatalogs`] response
pub fn build(self) -> Result<RecordBatch> {
let Self { catalogs } = self;
let Self { mut catalogs } = self;
catalogs.sort_unstable();

let batch = RecordBatch::try_new(
Arc::clone(&GET_CATALOG_SCHEMA),
Expand Down Expand Up @@ -98,3 +99,30 @@ static GET_CATALOG_SCHEMA: Lazy<SchemaRef> = Lazy::new(|| {
false,
)]))
});

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_catalogs_are_sorted() {
let batch = ["a_catalog", "c_catalog", "b_catalog"]
.into_iter()
.fold(GetCatalogsBuilder::new(), |mut builder, catalog| {
builder.append(catalog);
builder
})
.build()
.unwrap();
let catalogs = batch
.column(0)
.as_any()
.downcast_ref::<StringArray>()
.unwrap()
.iter()
.flatten()
.collect::<Vec<_>>();
assert!(catalogs.is_sorted());
assert_eq!(catalogs, ["a_catalog", "b_catalog", "c_catalog"]);
}
}

0 comments on commit c4dbf0d

Please sign in to comment.