alamb commented on a change in pull request #1386:
URL: https://github.com/apache/arrow-rs/pull/1386#discussion_r821107879



##########
File path: arrow-flight/src/sql/server.rs
##########
@@ -0,0 +1,458 @@
+// 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.
+
+use std::pin::Pin;
+
+use futures::Stream;
+use protobuf::Message;
+use tonic::{Request, Response, Status, Streaming};
+
+use super::{
+    super::{
+        flight_service_server::FlightService, Action, ActionType, Criteria, 
Empty,
+        FlightData, FlightDescriptor, FlightInfo, HandshakeRequest, 
HandshakeResponse,
+        PutResult, SchemaResult, Ticket,
+    },
+    ActionClosePreparedStatementRequest, ActionCreatePreparedStatementRequest,

Review comment:
       Let's try with the generated code then. If people decide it is too 
annoying to deal with, we can add some wrapper classes. 

##########
File path: arrow-flight/src/sql/arrow.flight.protocol.sql.rs
##########
@@ -0,0 +1,1169 @@
+// This file was automatically generated through the build.rs script, and 
should not be edited.
+
+///
+/// Represents a metadata request. Used in the command member of 
FlightDescriptor
+/// for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  info_name: uint32 not null,
+///  value: dense_union<
+///              string_value: utf8,
+///              bool_value: bool,
+///              bigint_value: int64,
+///              int32_bitmask: int32,
+///              string_list: list<string_data: utf8>
+///              int32_to_int32_list_map: map<key: int32, value: list<$data$: 
int32>>
+/// >
+/// where there is one row per requested piece of metadata information.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetSqlInfo {
+    ///
+    /// Values are modelled after ODBC's SQLGetInfo() function. This 
information is intended to provide
+    /// Flight SQL clients with basic, SQL syntax and SQL functions related 
information.
+    /// More information types can be added in future releases.
+    /// E.g. more SQL syntax support types, scalar functions support, type 
conversion support etc.
+    ///
+    /// Note that the set of metadata may expand.
+    ///
+    /// Initially, Flight SQL will support the following information types:
+    /// - Server Information - Range [0-500)
+    /// - Syntax Information - Range [500-1000)
+    /// Range [0-10,000) is reserved for defaults (see SqlInfo enum for 
default options).
+    /// Custom options should start at 10,000.
+    ///
+    /// If omitted, then all metadata will be retrieved.
+    /// Flight SQL Servers may choose to include additional metadata above and 
beyond the specified set, however they must
+    /// at least return the specified set. IDs ranging from 0 to 10,000 
(exclusive) are reserved for future use.
+    /// If additional metadata is included, the metadata IDs should start from 
10,000.
+    #[prost(uint32, repeated, tag = "1")]
+    pub info: ::prost::alloc::vec::Vec<u32>,
+}
+///
+/// Represents a request to retrieve the list of catalogs on a Flight SQL 
enabled backend.
+/// The definition of a catalog depends on vendor/implementation. It is 
usually the database itself
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  catalog_name: utf8 not null
+/// >
+/// The returned data should be ordered by catalog_name.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetCatalogs {}
+///
+/// Represents a request to retrieve the list of database schemas on a Flight 
SQL enabled backend.
+/// The definition of a database schema depends on vendor/implementation. It 
is usually a collection of tables.
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  catalog_name: utf8,
+///  db_schema_name: utf8 not null
+/// >
+/// The returned data should be ordered by catalog_name, then db_schema_name.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetDbSchemas {
+    ///
+    /// Specifies the Catalog to search for the tables.
+    /// An empty string retrieves those without a catalog.
+    /// If omitted the catalog name should not be used to narrow the search.
+    #[prost(string, optional, tag = "1")]
+    pub catalog: ::core::option::Option<::prost::alloc::string::String>,
+    ///
+    /// Specifies a filter pattern for schemas to search for.
+    /// When no db_schema_filter_pattern is provided, the pattern will not be 
used to narrow the search.
+    /// In the pattern string, two special characters can be used to denote 
matching rules:
+    ///    - "%" means to match any substring with 0 or more characters.
+    ///    - "_" means to match any one character.
+    #[prost(string, optional, tag = "2")]
+    pub db_schema_filter_pattern: 
::core::option::Option<::prost::alloc::string::String>,
+}
+///
+/// Represents a request to retrieve the list of tables, and optionally their 
schemas, on a Flight SQL enabled backend.
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  catalog_name: utf8,
+///  db_schema_name: utf8,
+///  table_name: utf8 not null,
+///  table_type: utf8 not null,
+///  \[optional\] table_schema: bytes not null (schema of the table as 
described in Schema.fbs::Schema,
+///                                           it is serialized as an IPC 
message.)
+/// >
+/// The returned data should be ordered by catalog_name, db_schema_name, 
table_name, then table_type, followed by table_schema if requested.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetTables {
+    ///
+    /// Specifies the Catalog to search for the tables.
+    /// An empty string retrieves those without a catalog.
+    /// If omitted the catalog name should not be used to narrow the search.
+    #[prost(string, optional, tag = "1")]
+    pub catalog: ::core::option::Option<::prost::alloc::string::String>,
+    ///
+    /// Specifies a filter pattern for schemas to search for.
+    /// When no db_schema_filter_pattern is provided, all schemas matching 
other filters are searched.
+    /// In the pattern string, two special characters can be used to denote 
matching rules:
+    ///    - "%" means to match any substring with 0 or more characters.
+    ///    - "_" means to match any one character.
+    #[prost(string, optional, tag = "2")]
+    pub db_schema_filter_pattern: 
::core::option::Option<::prost::alloc::string::String>,
+    ///
+    /// Specifies a filter pattern for tables to search for.
+    /// When no table_name_filter_pattern is provided, all tables matching 
other filters are searched.
+    /// In the pattern string, two special characters can be used to denote 
matching rules:
+    ///    - "%" means to match any substring with 0 or more characters.
+    ///    - "_" means to match any one character.
+    #[prost(string, optional, tag = "3")]
+    pub table_name_filter_pattern: 
::core::option::Option<::prost::alloc::string::String>,
+    ///
+    /// Specifies a filter of table types which must match.
+    /// The table types depend on vendor/implementation. It is usually used to 
separate tables from views or system tables.
+    /// TABLE, VIEW, and SYSTEM TABLE are commonly supported.
+    #[prost(string, repeated, tag = "4")]
+    pub table_types: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
+    /// Specifies if the Arrow schema should be returned for found tables.
+    #[prost(bool, tag = "5")]
+    pub include_schema: bool,
+}
+///
+/// Represents a request to retrieve the list of table types on a Flight SQL 
enabled backend.
+/// The table types depend on vendor/implementation. It is usually used to 
separate tables from views or system tables.
+/// TABLE, VIEW, and SYSTEM TABLE are commonly supported.
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  table_type: utf8 not null
+/// >
+/// The returned data should be ordered by table_type.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetTableTypes {}
+///
+/// Represents a request to retrieve the primary keys of a table on a Flight 
SQL enabled backend.
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  catalog_name: utf8,
+///  db_schema_name: utf8,
+///  table_name: utf8 not null,
+///  column_name: utf8 not null,
+///  key_name: utf8,
+///  key_sequence: int not null
+/// >
+/// The returned data should be ordered by catalog_name, db_schema_name, 
table_name, key_name, then key_sequence.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetPrimaryKeys {
+    ///
+    /// Specifies the catalog to search for the table.
+    /// An empty string retrieves those without a catalog.
+    /// If omitted the catalog name should not be used to narrow the search.
+    #[prost(string, optional, tag = "1")]
+    pub catalog: ::core::option::Option<::prost::alloc::string::String>,
+    ///
+    /// Specifies the schema to search for the table.
+    /// An empty string retrieves those without a schema.
+    /// If omitted the schema name should not be used to narrow the search.
+    #[prost(string, optional, tag = "2")]
+    pub db_schema: ::core::option::Option<::prost::alloc::string::String>,
+    /// Specifies the table to get the primary keys for.
+    #[prost(string, tag = "3")]
+    pub table: ::prost::alloc::string::String,
+}
+///
+/// Represents a request to retrieve a description of the foreign key columns 
that reference the given table's
+/// primary key columns (the foreign keys exported by a table) of a table on a 
Flight SQL enabled backend.
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  pk_catalog_name: utf8,
+///  pk_db_schema_name: utf8,
+///  pk_table_name: utf8 not null,
+///  pk_column_name: utf8 not null,
+///  fk_catalog_name: utf8,
+///  fk_db_schema_name: utf8,
+///  fk_table_name: utf8 not null,
+///  fk_column_name: utf8 not null,
+///  key_sequence: int not null,
+///  fk_key_name: utf8,
+///  pk_key_name: utf8,
+///  update_rule: uint1 not null,
+///  delete_rule: uint1 not null
+/// >
+/// The returned data should be ordered by fk_catalog_name, fk_db_schema_name, 
fk_table_name, fk_key_name, then key_sequence.
+/// update_rule and delete_rule returns a byte that is equivalent to actions 
declared on UpdateDeleteRules enum.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetExportedKeys {
+    ///
+    /// Specifies the catalog to search for the foreign key table.
+    /// An empty string retrieves those without a catalog.
+    /// If omitted the catalog name should not be used to narrow the search.
+    #[prost(string, optional, tag = "1")]
+    pub catalog: ::core::option::Option<::prost::alloc::string::String>,
+    ///
+    /// Specifies the schema to search for the foreign key table.
+    /// An empty string retrieves those without a schema.
+    /// If omitted the schema name should not be used to narrow the search.
+    #[prost(string, optional, tag = "2")]
+    pub db_schema: ::core::option::Option<::prost::alloc::string::String>,
+    /// Specifies the foreign key table to get the foreign keys for.
+    #[prost(string, tag = "3")]
+    pub table: ::prost::alloc::string::String,
+}
+///
+/// Represents a request to retrieve the foreign keys of a table on a Flight 
SQL enabled backend.
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  pk_catalog_name: utf8,
+///  pk_db_schema_name: utf8,
+///  pk_table_name: utf8 not null,
+///  pk_column_name: utf8 not null,
+///  fk_catalog_name: utf8,
+///  fk_db_schema_name: utf8,
+///  fk_table_name: utf8 not null,
+///  fk_column_name: utf8 not null,
+///  key_sequence: int not null,
+///  fk_key_name: utf8,
+///  pk_key_name: utf8,
+///  update_rule: uint1 not null,
+///  delete_rule: uint1 not null
+/// >
+/// The returned data should be ordered by pk_catalog_name, pk_db_schema_name, 
pk_table_name, pk_key_name, then key_sequence.
+/// update_rule and delete_rule returns a byte that is equivalent to actions:
+///    - 0 = CASCADE
+///    - 1 = RESTRICT
+///    - 2 = SET NULL
+///    - 3 = NO ACTION
+///    - 4 = SET DEFAULT
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetImportedKeys {
+    ///
+    /// Specifies the catalog to search for the primary key table.
+    /// An empty string retrieves those without a catalog.
+    /// If omitted the catalog name should not be used to narrow the search.
+    #[prost(string, optional, tag = "1")]
+    pub catalog: ::core::option::Option<::prost::alloc::string::String>,
+    ///
+    /// Specifies the schema to search for the primary key table.
+    /// An empty string retrieves those without a schema.
+    /// If omitted the schema name should not be used to narrow the search.
+    #[prost(string, optional, tag = "2")]
+    pub db_schema: ::core::option::Option<::prost::alloc::string::String>,
+    /// Specifies the primary key table to get the foreign keys for.
+    #[prost(string, tag = "3")]
+    pub table: ::prost::alloc::string::String,
+}
+///
+/// Represents a request to retrieve a description of the foreign key columns 
in the given foreign key table that
+/// reference the primary key or the columns representing a unique constraint 
of the parent table (could be the same
+/// or a different table) on a Flight SQL enabled backend.
+/// Used in the command member of FlightDescriptor for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the catalog metadata request.
+///
+/// The returned Arrow schema will be:
+/// <
+///  pk_catalog_name: utf8,
+///  pk_db_schema_name: utf8,
+///  pk_table_name: utf8 not null,
+///  pk_column_name: utf8 not null,
+///  fk_catalog_name: utf8,
+///  fk_db_schema_name: utf8,
+///  fk_table_name: utf8 not null,
+///  fk_column_name: utf8 not null,
+///  key_sequence: int not null,
+///  fk_key_name: utf8,
+///  pk_key_name: utf8,
+///  update_rule: uint1 not null,
+///  delete_rule: uint1 not null
+/// >
+/// The returned data should be ordered by pk_catalog_name, pk_db_schema_name, 
pk_table_name, pk_key_name, then key_sequence.
+/// update_rule and delete_rule returns a byte that is equivalent to actions:
+///    - 0 = CASCADE
+///    - 1 = RESTRICT
+///    - 2 = SET NULL
+///    - 3 = NO ACTION
+///    - 4 = SET DEFAULT
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandGetCrossReference {
+    ///*
+    /// The catalog name where the parent table is.
+    /// An empty string retrieves those without a catalog.
+    /// If omitted the catalog name should not be used to narrow the search.
+    #[prost(string, optional, tag = "1")]
+    pub pk_catalog: ::core::option::Option<::prost::alloc::string::String>,
+    ///*
+    /// The Schema name where the parent table is.
+    /// An empty string retrieves those without a schema.
+    /// If omitted the schema name should not be used to narrow the search.
+    #[prost(string, optional, tag = "2")]
+    pub pk_db_schema: ::core::option::Option<::prost::alloc::string::String>,
+    ///*
+    /// The parent table name. It cannot be null.
+    #[prost(string, tag = "3")]
+    pub pk_table: ::prost::alloc::string::String,
+    ///*
+    /// The catalog name where the foreign table is.
+    /// An empty string retrieves those without a catalog.
+    /// If omitted the catalog name should not be used to narrow the search.
+    #[prost(string, optional, tag = "4")]
+    pub fk_catalog: ::core::option::Option<::prost::alloc::string::String>,
+    ///*
+    /// The schema name where the foreign table is.
+    /// An empty string retrieves those without a schema.
+    /// If omitted the schema name should not be used to narrow the search.
+    #[prost(string, optional, tag = "5")]
+    pub fk_db_schema: ::core::option::Option<::prost::alloc::string::String>,
+    ///*
+    /// The foreign table name. It cannot be null.
+    #[prost(string, tag = "6")]
+    pub fk_table: ::prost::alloc::string::String,
+}
+// SQL Execution Action Messages
+
+///
+/// Request message for the "CreatePreparedStatement" action on a Flight SQL 
enabled backend.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct ActionCreatePreparedStatementRequest {
+    /// The valid SQL string to create a prepared statement for.
+    #[prost(string, tag = "1")]
+    pub query: ::prost::alloc::string::String,
+}
+///
+/// Wrap the result of a "GetPreparedStatement" action.
+///
+/// The resultant PreparedStatement can be closed either:
+/// - Manually, through the "ClosePreparedStatement" action;
+/// - Automatically, by a server timeout.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct ActionCreatePreparedStatementResult {
+    /// Opaque handle for the prepared statement on the server.
+    #[prost(bytes = "vec", tag = "1")]
+    pub prepared_statement_handle: ::prost::alloc::vec::Vec<u8>,
+    /// If a result set generating query was provided, dataset_schema contains 
the
+    /// schema of the dataset as described in Schema.fbs::Schema, it is 
serialized as an IPC message.
+    #[prost(bytes = "vec", tag = "2")]
+    pub dataset_schema: ::prost::alloc::vec::Vec<u8>,
+    /// If the query provided contained parameters, parameter_schema contains 
the
+    /// schema of the expected parameters as described in Schema.fbs::Schema, 
it is serialized as an IPC message.
+    #[prost(bytes = "vec", tag = "3")]
+    pub parameter_schema: ::prost::alloc::vec::Vec<u8>,
+}
+///
+/// Request message for the "ClosePreparedStatement" action on a Flight SQL 
enabled backend.
+/// Closes server resources associated with the prepared statement handle.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct ActionClosePreparedStatementRequest {
+    /// Opaque handle for the prepared statement on the server.
+    #[prost(bytes = "vec", tag = "1")]
+    pub prepared_statement_handle: ::prost::alloc::vec::Vec<u8>,
+}
+// SQL Execution Messages.
+
+///
+/// Represents a SQL query. Used in the command member of FlightDescriptor
+/// for the following RPC calls:
+///  - GetSchema: return the Arrow schema of the query.
+///  - GetFlightInfo: execute the query.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandStatementQuery {
+    /// The SQL syntax.
+    #[prost(string, tag = "1")]
+    pub query: ::prost::alloc::string::String,
+}
+///*
+/// Represents a ticket resulting from GetFlightInfo with a 
CommandStatementQuery.
+/// This should be used only once and treated as an opaque value, that is, 
clients should not attempt to parse this.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct TicketStatementQuery {
+    /// Unique identifier for the instance of the statement to execute.
+    #[prost(bytes = "vec", tag = "1")]
+    pub statement_handle: ::prost::alloc::vec::Vec<u8>,
+}
+///
+/// Represents an instance of executing a prepared statement. Used in the 
command member of FlightDescriptor for
+/// the following RPC calls:
+///  - DoPut: bind parameter values. All of the bound parameter sets will be 
executed as a single atomic execution.
+///  - GetFlightInfo: execute the prepared statement instance.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandPreparedStatementQuery {
+    /// Opaque handle for the prepared statement on the server.
+    #[prost(bytes = "vec", tag = "1")]
+    pub prepared_statement_handle: ::prost::alloc::vec::Vec<u8>,
+}
+///
+/// Represents a SQL update query. Used in the command member of 
FlightDescriptor
+/// for the the RPC call DoPut to cause the server to execute the included SQL 
update.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandStatementUpdate {
+    /// The SQL syntax.
+    #[prost(string, tag = "1")]
+    pub query: ::prost::alloc::string::String,
+}
+///
+/// Represents a SQL update query. Used in the command member of 
FlightDescriptor
+/// for the the RPC call DoPut to cause the server to execute the included
+/// prepared statement handle as an update.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct CommandPreparedStatementUpdate {
+    /// Opaque handle for the prepared statement on the server.
+    #[prost(bytes = "vec", tag = "1")]
+    pub prepared_statement_handle: ::prost::alloc::vec::Vec<u8>,
+}
+///
+/// Returned from the RPC call DoPut when a CommandStatementUpdate
+/// CommandPreparedStatementUpdate was in the request, containing
+/// results from the update.
+#[derive(Clone, PartialEq, ::prost::Message)]
+pub struct DoPutUpdateResult {
+    /// The number of records updated. A return value of -1 represents
+    /// an unknown updated record count.
+    #[prost(int64, tag = "1")]
+    pub record_count: i64,
+}
+/// Options for CommandGetSqlInfo.

Review comment:
       it is awesome that all these comments (from the protobuf) got kept




-- 
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]


Reply via email to