rafael-telles commented on a change in pull request #11507:
URL: https://github.com/apache/arrow/pull/11507#discussion_r756380788



##########
File path: cpp/src/arrow/flight/sql/server.h
##########
@@ -0,0 +1,495 @@
+// 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.
+
+// Interfaces to use for defining Flight RPC servers. API should be considered
+// experimental for now
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+
+#include "arrow/flight/server.h"
+#include "arrow/flight/sql/server.h"
+#include "arrow/flight/sql/sql_info_types.h"
+#include "arrow/util/optional.h"
+
+namespace arrow {
+namespace flight {
+namespace sql {
+
+struct StatementQuery {
+  std::string query;
+};
+
+struct StatementUpdate {
+  std::string query;
+};
+
+struct StatementQueryTicket {
+  std::string statement_handle;
+};
+
+struct PreparedStatementQuery {
+  std::string prepared_statement_handle;
+};
+
+struct PreparedStatementUpdate {
+  std::string prepared_statement_handle;
+};
+
+struct GetSqlInfo {
+  std::vector<int32_t> info;
+};
+
+struct GetSchemas {
+  util::optional<std::string> catalog;
+  util::optional<std::string> schema_filter_pattern;
+};
+
+struct GetTables {
+  util::optional<std::string> catalog;
+  util::optional<std::string> schema_filter_pattern;
+  util::optional<std::string> table_name_filter_pattern;
+  std::vector<std::string> table_types;
+  bool include_schema;
+};
+
+struct GetPrimaryKeys {
+  util::optional<std::string> catalog;
+  util::optional<std::string> schema;
+  std::string table;
+};
+
+struct GetExportedKeys {
+  util::optional<std::string> catalog;
+  util::optional<std::string> schema;
+  std::string table;
+};
+
+struct GetImportedKeys {
+  util::optional<std::string> catalog;
+  util::optional<std::string> schema;
+  std::string table;
+};
+
+struct GetCrossReference {
+  util::optional<std::string> pk_catalog;
+  util::optional<std::string> pk_schema;
+  std::string pk_table;
+  util::optional<std::string> fk_catalog;
+  util::optional<std::string> fk_schema;
+  std::string fk_table;
+};
+
+struct ActionCreatePreparedStatementRequest {
+  std::string query;
+};
+
+struct ActionClosePreparedStatementRequest {
+  std::string prepared_statement_handle;
+};
+
+struct ActionCreatePreparedStatementResult {
+  std::shared_ptr<Schema> dataset_schema;
+  std::shared_ptr<Schema> parameter_schema;
+  std::string prepared_statement_handle;
+};
+
+/// \brief A utility function to create a ticket for a statement query.
+///        Intended for Flight SQL server implementations.
+/// \param[in] statement_handle      The statement handle that will originate 
the ticket.
+/// \return                          The parsed ticket as an string.
+arrow::Result<std::string> CreateStatementQueryTicket(
+    const std::string& statement_handle);
+
+class ARROW_EXPORT FlightSqlServerBase : public FlightServerBase {
+ private:
+  SqlInfoResultMap sql_info_id_to_result_;
+
+ public:
+  Status GetFlightInfo(const ServerCallContext& context, const 
FlightDescriptor& request,
+                       std::unique_ptr<FlightInfo>* info) override;
+
+  Status DoGet(const ServerCallContext& context, const Ticket& request,
+               std::unique_ptr<FlightDataStream>* stream) override;
+
+  Status DoPut(const ServerCallContext& context,
+               std::unique_ptr<FlightMessageReader> reader,
+               std::unique_ptr<FlightMetadataWriter> writer) override;
+
+  const ActionType kCreatePreparedStatementActionType =
+      ActionType{"CreatePreparedStatement",
+                 "Creates a reusable prepared statement resource on the 
server.\n"
+                 "Request Message: ActionCreatePreparedStatementRequest\n"
+                 "Response Message: ActionCreatePreparedStatementResult"};
+  const ActionType kClosePreparedStatementActionType =
+      ActionType{"ClosePreparedStatement",
+                 "Closes a reusable prepared statement resource on the 
server.\n"
+                 "Request Message: ActionClosePreparedStatementRequest\n"
+                 "Response Message: N/A"};
+
+  Status ListActions(const ServerCallContext& context,
+                     std::vector<ActionType>* actions) override;
+
+  Status DoAction(const ServerCallContext& context, const Action& action,
+                  std::unique_ptr<ResultStream>* result) override;
+
+  /// \brief Gets a FlightInfo for executing a SQL query.
+  /// \param[in] context      Per-call context.
+  /// \param[in] command      The StatementQuery object containing the SQL 
statement.
+  /// \param[in] descriptor   The descriptor identifying the data stream.
+  /// \param[out] info        The FlightInfo describing where to access the 
dataset.
+  /// \return                 Status.
+  virtual Status GetFlightInfoStatement(const ServerCallContext& context,
+                                        const StatementQuery& command,
+                                        const FlightDescriptor& descriptor,
+                                        std::unique_ptr<FlightInfo>* info);
+
+  /// \brief Gets a FlightDataStream containing the query results.
+  /// \param[in] context      Per-call context.
+  /// \param[in] command      The StatementQueryTicket containing the 
statement handle.
+  /// \param[out] result      The FlightDataStream containing the results.
+  /// \return                 Status.
+  virtual Status DoGetStatement(const ServerCallContext& context,
+                                const StatementQueryTicket& command,
+                                std::unique_ptr<FlightDataStream>* result);
+
+  /// \brief Gets a FlightInfo for executing an already created prepared 
statement.
+  /// \param[in] context      Per-call context.
+  /// \param[in] command      The PreparedStatementQuery object containing the
+  ///                         prepared statement handle.
+  /// \param[in] descriptor   The descriptor identifying the data stream.
+  /// \param[out] info        The FlightInfo describing where to access the
+  ///                         dataset.
+  /// \return                 Status.
+  virtual Status GetFlightInfoPreparedStatement(const ServerCallContext& 
context,
+                                                const PreparedStatementQuery& 
command,
+                                                const FlightDescriptor& 
descriptor,
+                                                std::unique_ptr<FlightInfo>* 
info);
+
+  /// \brief Gets a FlightDataStream containing the prepared statement query 
results.
+  /// \param[in] context      Per-call context.
+  /// \param[in] command      The PreparedStatementQuery object containing the
+  ///                         prepared statement handle.
+  /// \param[out] result      The FlightDataStream containing the results.
+  /// \return                 Status.
+  virtual Status DoGetPreparedStatement(const ServerCallContext& context,
+                                        const PreparedStatementQuery& command,

Review comment:
       This is also supported.
   The user can make a `DoPut` passing data to be bound to these placeholders, 
I think this is better described in the proposal: 
https://docs.google.com/document/d/1WQz32bDF06GgMdEYyzhakqUigBZkALFwDF2y1x3DTAI/edit#heading=h.2s8eyo1




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