jcralmeida commented on a change in pull request #11507:
URL: https://github.com/apache/arrow/pull/11507#discussion_r746868379



##########
File path: cpp/src/arrow/flight/flight_sql/server.cc
##########
@@ -0,0 +1,663 @@
+// 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
+
+#include <arrow/api.h>
+#include <arrow/buffer.h>
+#include <arrow/flight/flight_sql/FlightSql.pb.h>
+#include <arrow/flight/flight_sql/server.h>
+#include <google/protobuf/any.pb.h>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/uuid/uuid.hpp>
+#include <sstream>
+
+#define PROPERTY_TO_OPTIONAL(COMMAND, PROPERTY) \
+  COMMAND.has_##PROPERTY() ? util::make_optional(COMMAND.PROPERTY()) : 
util::nullopt;
+
+namespace arrow {
+namespace flight {
+namespace sql {
+
+namespace pb = arrow::flight::protocol;
+
+arrow::Result<GetCrossReference> ParseCommandGetCrossReference(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandGetCrossReference command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandGetCrossReference.");
+  }
+
+  GetCrossReference result;
+  result.pk_catalog = PROPERTY_TO_OPTIONAL(command, pk_catalog);
+  result.pk_schema = PROPERTY_TO_OPTIONAL(command, pk_schema);
+  result.pk_table = command.pk_table();
+  result.fk_catalog = PROPERTY_TO_OPTIONAL(command, fk_catalog);
+  result.fk_schema = PROPERTY_TO_OPTIONAL(command, fk_schema);
+  result.fk_table = command.fk_table();
+  return result;
+}
+
+arrow::Result<GetImportedKeys> ParseCommandGetImportedKeys(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandGetImportedKeys command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandGetImportedKeys.");
+  }
+
+  GetImportedKeys result;
+  result.catalog = PROPERTY_TO_OPTIONAL(command, catalog);
+  result.schema = PROPERTY_TO_OPTIONAL(command, schema);
+  result.table = command.table();
+  return result;
+}
+
+arrow::Result<GetExportedKeys> ParseCommandGetExportedKeys(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandGetExportedKeys command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandGetExportedKeys.");
+  }
+
+  GetExportedKeys result;
+  result.catalog = PROPERTY_TO_OPTIONAL(command, catalog);
+  result.schema = PROPERTY_TO_OPTIONAL(command, schema);
+  result.table = command.table();
+  return result;
+}
+
+arrow::Result<GetPrimaryKeys> ParseCommandGetPrimaryKeys(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandGetPrimaryKeys command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandGetPrimaryKeys.");
+  }
+
+  GetPrimaryKeys result;
+  result.catalog = PROPERTY_TO_OPTIONAL(command, catalog);
+  result.schema = PROPERTY_TO_OPTIONAL(command, schema);
+  result.table = command.table();
+  return result;
+}
+
+arrow::Result<GetSqlInfo> ParseCommandGetSqlInfo(const google::protobuf::Any& 
any) {
+  pb::sql::CommandGetSqlInfo command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandGetSqlInfo.");
+  }
+
+  GetSqlInfo result;
+  return result;
+}
+
+arrow::Result<GetSchemas> ParseCommandGetSchemas(const google::protobuf::Any& 
any) {
+  pb::sql::CommandGetSchemas command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandGetSchemas.");
+  }
+
+  GetSchemas result;
+  result.catalog = PROPERTY_TO_OPTIONAL(command, catalog);
+  result.schema_filter_pattern = PROPERTY_TO_OPTIONAL(command, 
schema_filter_pattern);
+  return result;
+}
+
+arrow::Result<PreparedStatementQuery> ParseCommandPreparedStatementQuery(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandPreparedStatementQuery command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandPreparedStatementQuery.");
+  }
+
+  PreparedStatementQuery result;
+  result.prepared_statement_handle = command.prepared_statement_handle();
+  return result;
+}
+
+arrow::Result<StatementQuery> ParseCommandStatementQuery(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandStatementQuery command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandStatementQuery.");
+  }
+
+  StatementQuery result;
+  result.query = command.query();
+  return result;
+}
+
+arrow::Result<GetTables> ParseCommandGetTables(const google::protobuf::Any& 
any) {
+  pb::sql::CommandGetTables command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandGetTables.");
+  }
+
+  std::vector<std::string> table_types(command.table_types_size());
+  std::copy(command.table_types().begin(), command.table_types().end(),
+            table_types.begin());
+
+  GetTables result;
+  result.catalog = PROPERTY_TO_OPTIONAL(command, catalog);
+  result.schema_filter_pattern = PROPERTY_TO_OPTIONAL(command, 
schema_filter_pattern);
+  result.table_name_filter_pattern =
+      PROPERTY_TO_OPTIONAL(command, table_name_filter_pattern);
+  result.table_types = table_types;
+  result.include_schema = command.include_schema();
+  return result;
+}
+
+arrow::Result<StatementQueryTicket> ParseStatementQueryTicket(
+    const google::protobuf::Any& any) {
+  pb::sql::TicketStatementQuery command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack TicketStatementQuery.");
+  }
+
+  StatementQueryTicket result;
+  result.statement_handle = command.statement_handle();
+  return result;
+}
+
+arrow::Result<StatementUpdate> ParseCommandStatementUpdate(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandStatementUpdate command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandStatementUpdate.");
+  }
+
+  StatementUpdate result;
+  result.query = command.query();
+  return result;
+}
+
+arrow::Result<PreparedStatementUpdate> ParseCommandPreparedStatementUpdate(
+    const google::protobuf::Any& any) {
+  pb::sql::CommandPreparedStatementUpdate command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack CommandPreparedStatementUpdate.");
+  }
+
+  PreparedStatementUpdate result;
+  result.prepared_statement_handle = command.prepared_statement_handle();
+  return result;
+}
+
+arrow::Result<ActionCreatePreparedStatementRequest>
+ParseActionCreatePreparedStatementRequest(const google::protobuf::Any& any) {
+  pb::sql::ActionCreatePreparedStatementRequest command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack 
ActionCreatePreparedStatementRequest.");
+  }
+
+  ActionCreatePreparedStatementRequest result;
+  result.query = command.query();
+  return result;
+}
+
+arrow::Result<ActionClosePreparedStatementRequest>
+ParseActionClosePreparedStatementRequest(const google::protobuf::Any& any) {
+  pb::sql::ActionClosePreparedStatementRequest command;
+  if (!any.UnpackTo(&command)) {
+    return Status::Invalid("Unable to unpack 
ActionClosePreparedStatementRequest.");
+  }
+
+  ActionClosePreparedStatementRequest result;
+  result.prepared_statement_handle = command.prepared_statement_handle();
+  return result;
+}
+
+std::string FlightSqlServerBase::CreateStatementQueryTicket(

Review comment:
       This method is used in another classm so I can't remove from the header. 
I can transform it to a free function. Does it work?




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