lidavidm commented on a change in pull request #11507: URL: https://github.com/apache/arrow/pull/11507#discussion_r739235905
########## File path: cpp/src/arrow/flight/flight-sql/client.h ########## @@ -0,0 +1,233 @@ +// 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. + +#pragma once + +#include <arrow/flight/Flight.pb.h> +#include <arrow/flight/client.h> +#include <arrow/flight/flight-sql/FlightSql.pb.h> +#include <arrow/flight/types.h> +#include <arrow/result.h> +#include <arrow/status.h> +#include <google/protobuf/message.h> + +namespace pb = arrow::flight::protocol; + +namespace arrow { +namespace flight { +namespace sql { + +namespace internal { +class FlightClientImpl; +} + +/// \brief Flight client with Flight SQL semantics. +class ARROW_EXPORT FlightSqlClient { + private: + std::shared_ptr<internal::FlightClientImpl> impl_; + + public: + class PreparedStatement; + + explicit FlightSqlClient(std::shared_ptr<internal::FlightClientImpl> client); + + ~FlightSqlClient(); + + /// \brief Execute a query on the server. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] query The query to be executed in the UTF-8 format. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> Execute(const FlightCallOptions& options, + const std::string& query) const; + + /// \brief Execute an update query on the server. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] query The query to be executed in the UTF-8 format. + /// \return The quantity of rows affected by the operation. + arrow::Result<int64_t> ExecuteUpdate(const FlightCallOptions& options, + const std::string& query) const; + + /// \brief Request a list of catalogs. + /// \param[in] options RPC-layer hints for this call. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetCatalogs( + const FlightCallOptions& options) const; + + /// \brief Request a list of schemas. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] catalog The catalog. + /// \param[in] schema_filter_pattern The schema filter pattern. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetSchemas( + const FlightCallOptions& options, const std::string* catalog, + const std::string* schema_filter_pattern) const; + + /// \brief Given a flight ticket and schema, request to be sent the + /// stream. Returns record batch stream reader + /// \param[in] options Per-RPC options + /// \param[in] ticket The flight ticket to use + /// \return The returned RecordBatchReader + arrow::Result<std::unique_ptr<FlightStreamReader>> DoGet( + const FlightCallOptions& options, const Ticket& ticket) const; + + /// \brief Request a list of tables. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] catalog The catalog. + /// \param[in] schema_filter_pattern The schema filter pattern. + /// \param[in] table_filter_pattern The table filter pattern. + /// \param[in] include_schema True to include the schema upon return, + /// false to not include the schema. + /// \param[in] table_types The table types to include. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetTables( + const FlightCallOptions& options, const std::string* catalog, + const std::string* schema_filter_pattern, const std::string* table_filter_pattern, + bool include_schema, std::vector<std::string>& table_types) const; + + /// \brief Request the primary keys for a table. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] catalog The catalog. + /// \param[in] schema The schema. + /// \param[in] table The table. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetPrimaryKeys( + const FlightCallOptions& options, const std::string* catalog, + const std::string* schema, const std::string& table) const; + + /// \brief Retrieves a description about the foreign key columns that reference the + /// primary key columns of the given table. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] catalog The foreign key table catalog. + /// \param[in] schema The foreign key table schema. + /// \param[in] table The foreign key table. Cannot be null. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetExportedKeys( + const FlightCallOptions& options, const std::string* catalog, + const std::string* schema, const std::string& table) const; + + /// \brief Retrieves the foreign key columns for the given table. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] catalog The primary key table catalog. + /// \param[in] schema The primary key table schema. + /// \param[in] table The primary key table. Cannot be null. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetImportedKeys( + const FlightCallOptions& options, const std::string* catalog, + const std::string* schema, const std::string& table) const; + + /// \brief Retrieves 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). + /// \param[in] options RPC-layer hints for this call. + /// \param[in] pk_catalog The catalog of the table that exports the key. + /// \param[in] pk_schema The schema of the table that exports the key. + /// \param[in] pk_table The table that exports the key. + /// \param[in] fk_catalog The catalog of the table that imports the key. + /// \param[in] fk_schema The schema of the table that imports the key. + /// \param[in] fk_table The table that imports the key. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetCrossReference( + const FlightCallOptions& options, const std::string* pk_catalog, + const std::string* pk_schema, const std::string& pk_table, + const std::string* fk_catalog, const std::string* fk_schema, + const std::string& fk_table) const; + + /// \brief Request a list of table types. + /// \param[in] options RPC-layer hints for this call. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetTableTypes( + const FlightCallOptions& options) const; + + /// \brief Request a list of SQL information. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] sql_info the SQL info required. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetSqlInfo( + const FlightCallOptions& options, const std::vector<int>& sql_info) const; + + /// \brief Request a list of SQL information. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] sql_info the SQL info required. + /// \return The FlightInfo describing where to access the dataset. + arrow::Result<std::unique_ptr<FlightInfo>> GetSqlInfo( + const FlightCallOptions& options, + const std::vector<pb::sql::SqlInfo>& sql_info) const; + + /// \brief Create a prepared statement object. + /// \param[in] options RPC-layer hints for this call. + /// \param[in] query The query that will be executed. + /// \return The created prepared statement. + arrow::Result<std::shared_ptr<PreparedStatement>> Prepare( + const FlightCallOptions& options, const std::string& query); + + explicit FlightSqlClient(std::unique_ptr<FlightClient> client); + + class PreparedStatement { + std::shared_ptr<internal::FlightClientImpl> client_; + FlightCallOptions options_; + pb::sql::ActionCreatePreparedStatementResult prepared_statement_result_; + std::shared_ptr<RecordBatch> parameter_binding_; + bool is_closed_; + + public: + /// \brief Constructor for the PreparedStatement class. + /// \param[in] query The query that will be executed. + PreparedStatement( Review comment: note that Doxygen complains here since only one of the parameters is documented. -- 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]
