arrow_flight/sql/metadata/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Builders and function for building responses to FlightSQL metadata
19//! / information schema requests.
20//!
21//! - [`GetCatalogsBuilder`] for building responses to [`CommandGetCatalogs`] queries.
22//! - [`GetDbSchemasBuilder`] for building responses to [`CommandGetDbSchemas`] queries.
23//! - [`GetTablesBuilder`]for building responses to [`CommandGetTables`] queries.
24//! - [`SqlInfoDataBuilder`]for building responses to [`CommandGetSqlInfo`] queries.
25//! - [`XdbcTypeInfoDataBuilder`]for building responses to [`CommandGetXdbcTypeInfo`] queries.
26//!
27//! [`CommandGetCatalogs`]: crate::sql::CommandGetCatalogs
28//! [`CommandGetDbSchemas`]: crate::sql::CommandGetDbSchemas
29//! [`CommandGetTables`]: crate::sql::CommandGetTables
30//! [`CommandGetSqlInfo`]: crate::sql::CommandGetSqlInfo
31//! [`CommandGetXdbcTypeInfo`]: crate::sql::CommandGetXdbcTypeInfo
32
33mod catalogs;
34mod db_schemas;
35mod sql_info;
36mod table_types;
37mod tables;
38mod xdbc_info;
39
40pub use catalogs::GetCatalogsBuilder;
41pub use db_schemas::GetDbSchemasBuilder;
42pub use sql_info::{SqlInfoData, SqlInfoDataBuilder};
43pub use tables::GetTablesBuilder;
44pub use xdbc_info::{XdbcTypeInfo, XdbcTypeInfoData, XdbcTypeInfoDataBuilder};
45
46use arrow_array::ArrayRef;
47use arrow_array::UInt32Array;
48use arrow_row::RowConverter;
49use arrow_row::SortField;
50
51/// Helper function to sort all the columns in an array
52fn lexsort_to_indices(arrays: &[ArrayRef]) -> UInt32Array {
53    let fields = arrays
54        .iter()
55        .map(|a| SortField::new(a.data_type().clone()))
56        .collect();
57    let converter = RowConverter::new(fields).unwrap();
58    let rows = converter.convert_columns(arrays).unwrap();
59    let mut sort: Vec<_> = rows.iter().enumerate().collect();
60    sort.sort_unstable_by(|(_, a), (_, b)| a.cmp(b));
61    UInt32Array::from_iter_values(sort.iter().map(|(i, _)| *i as u32))
62}
63
64#[cfg(test)]
65mod tests {
66    use arrow_array::RecordBatch;
67    use arrow_cast::pretty::pretty_format_batches;
68    pub fn assert_batches_eq(batches: &[RecordBatch], expected_lines: &[&str]) {
69        let formatted = pretty_format_batches(batches).unwrap().to_string();
70        let actual_lines: Vec<_> = formatted.trim().lines().collect();
71        assert_eq!(
72            &actual_lines, expected_lines,
73            "\n\nexpected:\n\n{:#?}\nactual:\n\n{:#?}\n\n",
74            expected_lines, actual_lines
75        );
76    }
77}