alamb commented on code in PR #4359:
URL: https://github.com/apache/arrow-rs/pull/4359#discussion_r1218581209
##########
arrow-flight/src/sql/metadata/xdbc_info.rs:
##########
@@ -76,15 +75,13 @@ impl From<CommandGetXdbcTypeInfo> for Option<i32> {
/// [`CommandGetXdbcTypeInfo`] are metadata requests used by a Flight SQL
/// server to communicate supported capabilities to Flight SQL clients.
///
-/// Servers constuct a [`XdbcTypeInfoList`] via the
[`XdbcTypeInfoListBuilder`],
-/// and build responses using the [`encode`] method.
-///
-/// [`encode`]: XdbcTypeInfoList::encode
-pub struct XdbcTypeInfoList {
+/// Servers constuct - usually static - [`XdbcTypeInfoData`] via the
[XdbcTypeInfoDataBuilder`],
Review Comment:
👍
##########
arrow-flight/src/sql/metadata/xdbc_info.rs:
##########
@@ -0,0 +1,441 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Helpers for [`CommandGetXdbcTypeInfo`] metadata requests.
+//!
+//! - [`XdbcTypeInfo`] - a typed struct that holds the xdbc info corresponding
to expected schema.
+//! - [`XdbcTypeInfoListBuilder`] - a builder for collecting type infos
+//! and building a conformant `RecordBatch`.
+//! - [`XdbcTypeInfoList`] - a helper type wrapping a `RecordBatch`
+//! used for handling [`CommandGetXdbcTypeInfo`] requests.
+//!
+use std::sync::Arc;
+
+use arrow_array::builder::{BooleanBuilder, Int32Builder, ListBuilder,
StringBuilder};
+use arrow_array::cast::downcast_array;
+use arrow_array::{ArrayRef, Int32Array, ListArray, RecordBatch};
+use arrow_ord::comparison::eq_scalar;
+use arrow_schema::{DataType, Field, Schema, SchemaRef};
+use arrow_select::filter::filter_record_batch;
+use arrow_select::take::take;
+use once_cell::sync::Lazy;
+
+use super::lexsort_to_indices;
+use crate::error::*;
+use crate::sql::{
+ CommandGetXdbcTypeInfo, Nullable, Searchable, XdbcDataType,
XdbcDatetimeSubcode,
+};
+
+/// Data structure representing type information for xdbc types.
+#[derive(Debug, Clone, Default)]
+pub struct XdbcTypeInfo {
+ pub type_name: String,
+ pub data_type: XdbcDataType,
+ pub column_size: Option<i32>,
+ pub literal_prefix: Option<String>,
+ pub literal_suffix: Option<String>,
+ pub create_params: Option<Vec<String>>,
+ pub nullable: Nullable,
+ pub case_sensitive: bool,
+ pub searchable: Searchable,
+ pub unsigned_attribute: Option<bool>,
+ pub fixed_prec_scale: bool,
+ pub auto_increment: Option<bool>,
+ pub local_type_name: Option<String>,
+ pub minimum_scale: Option<i32>,
+ pub maximum_scale: Option<i32>,
+ pub sql_data_type: XdbcDataType,
+ pub datetime_subcode: Option<XdbcDatetimeSubcode>,
+ pub num_prec_radix: Option<i32>,
+ pub interval_precision: Option<i32>,
+}
+
+impl From<CommandGetXdbcTypeInfo> for Option<i32> {
Review Comment:
I wonder if we still need this `From` impl 🤔
##########
arrow-flight/src/sql/metadata/xdbc_info.rs:
##########
@@ -0,0 +1,441 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Helpers for [`CommandGetXdbcTypeInfo`] metadata requests.
+//!
+//! - [`XdbcTypeInfo`] - a typed struct that holds the xdbc info corresponding
to expected schema.
+//! - [`XdbcTypeInfoListBuilder`] - a builder for collecting type infos
+//! and building a conformant `RecordBatch`.
+//! - [`XdbcTypeInfoList`] - a helper type wrapping a `RecordBatch`
+//! used for handling [`CommandGetXdbcTypeInfo`] requests.
+//!
+use std::sync::Arc;
+
+use arrow_array::builder::{BooleanBuilder, Int32Builder, ListBuilder,
StringBuilder};
+use arrow_array::cast::downcast_array;
+use arrow_array::{ArrayRef, Int32Array, ListArray, RecordBatch};
+use arrow_ord::comparison::eq_scalar;
+use arrow_schema::{DataType, Field, Schema, SchemaRef};
+use arrow_select::filter::filter_record_batch;
+use arrow_select::take::take;
+use once_cell::sync::Lazy;
+
+use super::lexsort_to_indices;
+use crate::error::*;
+use crate::sql::{
+ CommandGetXdbcTypeInfo, Nullable, Searchable, XdbcDataType,
XdbcDatetimeSubcode,
+};
+
+/// Data structure representing type information for xdbc types.
+#[derive(Debug, Clone, Default)]
+pub struct XdbcTypeInfo {
+ pub type_name: String,
+ pub data_type: XdbcDataType,
+ pub column_size: Option<i32>,
+ pub literal_prefix: Option<String>,
+ pub literal_suffix: Option<String>,
+ pub create_params: Option<Vec<String>>,
+ pub nullable: Nullable,
+ pub case_sensitive: bool,
+ pub searchable: Searchable,
+ pub unsigned_attribute: Option<bool>,
+ pub fixed_prec_scale: bool,
+ pub auto_increment: Option<bool>,
+ pub local_type_name: Option<String>,
+ pub minimum_scale: Option<i32>,
+ pub maximum_scale: Option<i32>,
+ pub sql_data_type: XdbcDataType,
+ pub datetime_subcode: Option<XdbcDatetimeSubcode>,
+ pub num_prec_radix: Option<i32>,
+ pub interval_precision: Option<i32>,
+}
+
+impl From<CommandGetXdbcTypeInfo> for Option<i32> {
+ fn from(value: CommandGetXdbcTypeInfo) -> Self {
+ value.data_type
+ }
+}
+
+/// Helper to create [`CommandGetXdbcTypeInfo`] responses.
+///
+/// [`CommandGetXdbcTypeInfo`] are metadata requests used by a Flight SQL
+/// server to communicate supported capabilities to Flight SQL clients.
+///
+/// Servers constuct - usually static - [`XdbcTypeInfoData`] via the
[XdbcTypeInfoDataBuilder`],
+/// and build responses by passing the [`GetXdbcTypeInfoBuilder`].
+pub struct XdbcTypeInfoData {
+ batch: RecordBatch,
+}
+
+impl XdbcTypeInfoData {
+ /// Return the raw (not encoded) RecordBatch that will be returned
+ /// from [`CommandGetXdbcTypeInfo`]
+ pub fn record_batch(&self, data_type: impl Into<Option<i32>>) ->
Result<RecordBatch> {
+ if let Some(dt) = data_type.into() {
+ let arr: Int32Array =
downcast_array(self.batch.column(1).as_ref());
+ let filter = eq_scalar(&arr, dt)?;
+ Ok(filter_record_batch(&self.batch, &filter)?)
+ } else {
+ Ok(self.batch.clone())
+ }
+ }
+
+ /// Return the schema of the RecordBatch that will be returned
+ /// from [`CommandGetXdbcTypeInfo`]
+ pub fn schema(&self) -> SchemaRef {
+ self.batch.schema()
+ }
+}
+
+pub struct XdbcTypeInfoDataBuilder {
+ infos: Vec<XdbcTypeInfo>,
+}
+
+impl Default for XdbcTypeInfoDataBuilder {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+/// A builder for [`XdbcTypeInfoList`] which is used to create
[`CommandGetXdbcTypeInfo`].responses.
Review Comment:
```suggestion
/// A builder for [`XdbcTypeInfoList`] which is used to create
[`CommandGetXdbcTypeInfo`] responses.
```
##########
arrow-flight/examples/flight_sql_server.rs:
##########
@@ -367,12 +395,20 @@ impl FlightSqlService for FlightSqlServiceImpl {
async fn get_flight_info_xdbc_type_info(
&self,
- _query: CommandGetXdbcTypeInfo,
- _request: Request<FlightDescriptor>,
+ query: CommandGetXdbcTypeInfo,
+ request: Request<FlightDescriptor>,
) -> Result<Response<FlightInfo>, Status> {
- Err(Status::unimplemented(
- "get_flight_info_xdbc_type_info not implemented",
- ))
+ let flight_descriptor = request.into_inner();
+ let ticket = Ticket::new(query.encode_to_vec());
+ let endpoint = FlightEndpoint::new().with_ticket(ticket);
+
+ let flight_info = FlightInfo::new()
+ .try_with_schema(INSTANCE_XDBC_INFO.schema().as_ref())
Review Comment:
This probably needs to be updated to just use `query.into_builder()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]