From 6d388483e6ea5c7adeae522e51ac3c305d4f9d25 Mon Sep 17 00:00:00 2001
From: David Li
Date: Fri, 24 Jun 2022 15:18:19 -0400
Subject: [PATCH] ARROW-16902: [C++][FlightRPC] Fix DLL linkage in Flight SQL
---
.github/workflows/cpp.yml | 1 +
appveyor.yml | 2 ++
ci/appveyor-cpp-build.bat | 1 +
cpp/src/arrow/flight/sql/CMakeLists.txt | 9 +++++
cpp/src/arrow/flight/sql/client.cc | 3 ++
cpp/src/arrow/flight/sql/client.h | 4 +--
cpp/src/arrow/flight/sql/client_test.cc | 3 ++
cpp/src/arrow/flight/sql/column_metadata.h | 5 +--
cpp/src/arrow/flight/sql/server.cc | 3 ++
cpp/src/arrow/flight/sql/server.h | 37 ++++++++++----------
cpp/src/arrow/flight/sql/sql_info_internal.h | 3 +-
cpp/src/arrow/flight/sql/types.h | 5 +--
12 files changed, 51 insertions(+), 25 deletions(-)
diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml
index b914b7df52f6b..0e550710d6e1b 100644
--- a/.github/workflows/cpp.yml
+++ b/.github/workflows/cpp.yml
@@ -275,6 +275,7 @@ jobs:
ARROW_BUILD_TYPE: release
ARROW_DATASET: ON
ARROW_FLIGHT: ON
+ ARROW_FLIGHT_SQL: ON
ARROW_GANDIVA: ON
# google-could-cpp uses _dupenv_s() but it can't be used with msvcrt.
# We need to use ucrt to use _dupenv_s().
diff --git a/appveyor.yml b/appveyor.yml
index 2699e479b79f9..03a3597c9b7ba 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -46,6 +46,7 @@ environment:
CLCACHE_COMPRESS: 1
CLCACHE_COMPRESSLEVEL: 6
ARROW_BUILD_FLIGHT: "OFF"
+ ARROW_BUILD_FLIGHT_SQL: "OFF"
ARROW_BUILD_GANDIVA: "OFF"
ARROW_LLVM_VERSION: "7.0.*"
ARROW_S3: "OFF"
@@ -60,6 +61,7 @@ environment:
ARROW_GCS: "ON"
ARROW_S3: "ON"
ARROW_BUILD_FLIGHT: "ON"
+ ARROW_BUILD_FLIGHT_SQL: "ON"
ARROW_BUILD_GANDIVA: "ON"
- JOB: "Build_Debug"
GENERATOR: Ninja
diff --git a/ci/appveyor-cpp-build.bat b/ci/appveyor-cpp-build.bat
index e9441c63e2099..e7fea480b4f43 100644
--- a/ci/appveyor-cpp-build.bat
+++ b/ci/appveyor-cpp-build.bat
@@ -103,6 +103,7 @@ cmake -G "%GENERATOR%" %CMAKE_ARGS% ^
-DARROW_DATASET=ON ^
-DARROW_ENABLE_TIMING_TESTS=OFF ^
-DARROW_FLIGHT=%ARROW_BUILD_FLIGHT% ^
+ -DARROW_FLIGHT_SQL=%ARROW_BUILD_FLIGHT_SQL% ^
-DARROW_GANDIVA=%ARROW_BUILD_GANDIVA% ^
-DARROW_MIMALLOC=ON ^
-DARROW_PARQUET=ON ^
diff --git a/cpp/src/arrow/flight/sql/CMakeLists.txt b/cpp/src/arrow/flight/sql/CMakeLists.txt
index 1f5a72b50dad5..62d2c208d0942 100644
--- a/cpp/src/arrow/flight/sql/CMakeLists.txt
+++ b/cpp/src/arrow/flight/sql/CMakeLists.txt
@@ -33,6 +33,11 @@ add_custom_command(OUTPUT ${FLIGHT_SQL_GENERATED_PROTO_FILES}
DEPENDS ${PROTO_DEPENDS})
set_source_files_properties(${FLIGHT_SQL_GENERATED_PROTO_FILES} PROPERTIES GENERATED TRUE)
+if(MSVC)
+ # Suppress warnings caused by Protobuf (casts, dll-interface)
+ set_source_files_properties(${FLIGHT_SQL_GENERATED_PROTO_FILES}
+ PROPERTIES COMPILE_FLAGS "/wd4251 /wd4267")
+endif()
add_custom_target(flight_sql_protobuf_gen ALL DEPENDS ${FLIGHT_SQL_GENERATED_PROTO_FILES})
@@ -63,6 +68,10 @@ add_arrow_lib(arrow_flight_sql
PRIVATE_INCLUDES
"${Protobuf_INCLUDE_DIRS}")
+foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_LIBRARIES})
+ target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_EXPORTING)
+endforeach()
+
if(ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static" AND ARROW_BUILD_STATIC)
set(ARROW_FLIGHT_SQL_TEST_LINK_LIBS arrow_flight_sql_static)
else()
diff --git a/cpp/src/arrow/flight/sql/client.cc b/cpp/src/arrow/flight/sql/client.cc
index 89cfb3aad03f6..3ce220491f173 100644
--- a/cpp/src/arrow/flight/sql/client.cc
+++ b/cpp/src/arrow/flight/sql/client.cc
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+// Platform-specific defines
+#include "arrow/flight/platform.h"
+
#include "arrow/flight/sql/client.h"
#include
diff --git a/cpp/src/arrow/flight/sql/client.h b/cpp/src/arrow/flight/sql/client.h
index 78c162e4cda22..0b83a6edc6243 100644
--- a/cpp/src/arrow/flight/sql/client.h
+++ b/cpp/src/arrow/flight/sql/client.h
@@ -35,7 +35,7 @@ class PreparedStatement;
/// \brief Flight client with Flight SQL semantics.
///
/// Wraps a Flight client to provide the Flight SQL RPC calls.
-class ARROW_EXPORT FlightSqlClient {
+class ARROW_FLIGHT_EXPORT FlightSqlClient {
friend class PreparedStatement;
private:
@@ -202,7 +202,7 @@ class ARROW_EXPORT FlightSqlClient {
};
/// \brief A prepared statement that can be executed.
-class ARROW_EXPORT PreparedStatement {
+class ARROW_FLIGHT_EXPORT PreparedStatement {
public:
/// \brief Create a new prepared statement. However, applications
/// should generally use FlightSqlClient::Prepare.
diff --git a/cpp/src/arrow/flight/sql/client_test.cc b/cpp/src/arrow/flight/sql/client_test.cc
index 1cfce2520f50d..b29af7c46681d 100644
--- a/cpp/src/arrow/flight/sql/client_test.cc
+++ b/cpp/src/arrow/flight/sql/client_test.cc
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+// Platform-specific defines
+#include "arrow/flight/platform.h"
+
#include "arrow/flight/client.h"
#include
diff --git a/cpp/src/arrow/flight/sql/column_metadata.h b/cpp/src/arrow/flight/sql/column_metadata.h
index 08e7c64aeec07..7d6c74e012aa2 100644
--- a/cpp/src/arrow/flight/sql/column_metadata.h
+++ b/cpp/src/arrow/flight/sql/column_metadata.h
@@ -19,6 +19,7 @@
#include
+#include "arrow/flight/visibility.h"
#include "arrow/util/key_value_metadata.h"
namespace arrow {
@@ -26,7 +27,7 @@ namespace flight {
namespace sql {
/// \brief Helper class to set column metadata.
-class ColumnMetadata {
+class ARROW_FLIGHT_EXPORT ColumnMetadata {
private:
std::shared_ptr metadata_map_;
@@ -114,7 +115,7 @@ class ColumnMetadata {
const std::shared_ptr& metadata_map() const;
/// \brief A builder class to construct the ColumnMetadata object.
- class ColumnMetadataBuilder {
+ class ARROW_FLIGHT_EXPORT ColumnMetadataBuilder {
public:
friend class ColumnMetadata;
diff --git a/cpp/src/arrow/flight/sql/server.cc b/cpp/src/arrow/flight/sql/server.cc
index 5ad1be466e11e..c82146de86da3 100644
--- a/cpp/src/arrow/flight/sql/server.cc
+++ b/cpp/src/arrow/flight/sql/server.cc
@@ -18,6 +18,9 @@
// Interfaces to use for defining Flight RPC servers. API should be considered
// experimental for now
+// Platform-specific defines
+#include "arrow/flight/platform.h"
+
#include "arrow/flight/sql/server.h"
#include
diff --git a/cpp/src/arrow/flight/sql/server.h b/cpp/src/arrow/flight/sql/server.h
index 4e6ddce239746..1875ec8f7a769 100644
--- a/cpp/src/arrow/flight/sql/server.h
+++ b/cpp/src/arrow/flight/sql/server.h
@@ -39,43 +39,43 @@ namespace sql {
/// @{
/// \brief A SQL query.
-struct StatementQuery {
+struct ARROW_FLIGHT_EXPORT StatementQuery {
/// \brief The SQL query.
std::string query;
};
/// \brief A SQL update query.
-struct StatementUpdate {
+struct ARROW_FLIGHT_EXPORT StatementUpdate {
/// \brief The SQL query.
std::string query;
};
/// \brief A request to execute a query.
-struct StatementQueryTicket {
+struct ARROW_FLIGHT_EXPORT StatementQueryTicket {
/// \brief The server-generated opaque identifier for the query.
std::string statement_handle;
};
/// \brief A prepared query statement.
-struct PreparedStatementQuery {
+struct ARROW_FLIGHT_EXPORT PreparedStatementQuery {
/// \brief The server-generated opaque identifier for the statement.
std::string prepared_statement_handle;
};
/// \brief A prepared update statement.
-struct PreparedStatementUpdate {
+struct ARROW_FLIGHT_EXPORT PreparedStatementUpdate {
/// \brief The server-generated opaque identifier for the statement.
std::string prepared_statement_handle;
};
/// \brief A request to fetch server metadata.
-struct GetSqlInfo {
+struct ARROW_FLIGHT_EXPORT GetSqlInfo {
/// \brief A list of metadata IDs to fetch.
std::vector info;
};
/// \brief A request to list database schemas.
-struct GetDbSchemas {
+struct ARROW_FLIGHT_EXPORT GetDbSchemas {
/// \brief An optional database catalog to filter on.
util::optional catalog;
/// \brief An optional database schema to filter on.
@@ -83,7 +83,7 @@ struct GetDbSchemas {
};
/// \brief A request to list database tables.
-struct GetTables {
+struct ARROW_FLIGHT_EXPORT GetTables {
/// \brief An optional database catalog to filter on.
util::optional catalog;
/// \brief An optional database schema to filter on.
@@ -97,33 +97,33 @@ struct GetTables {
};
/// \brief A request to get SQL data type information.
-struct GetXdbcTypeInfo {
+struct ARROW_FLIGHT_EXPORT GetXdbcTypeInfo {
/// \brief A specific SQL type ID to fetch information about.
util::optional data_type;
};
/// \brief A request to list primary keys of a table.
-struct GetPrimaryKeys {
+struct ARROW_FLIGHT_EXPORT GetPrimaryKeys {
/// \brief The given table.
TableRef table_ref;
};
/// \brief A request to list foreign key columns referencing primary key
/// columns of a table.
-struct GetExportedKeys {
+struct ARROW_FLIGHT_EXPORT GetExportedKeys {
/// \brief The given table.
TableRef table_ref;
};
/// \brief A request to list foreign keys of a table.
-struct GetImportedKeys {
+struct ARROW_FLIGHT_EXPORT GetImportedKeys {
/// \brief The given table.
TableRef table_ref;
};
/// \brief A request to list foreign key columns of a table that
/// reference columns in a given parent table.
-struct GetCrossReference {
+struct ARROW_FLIGHT_EXPORT GetCrossReference {
/// \brief The parent table (the one containing referenced columns).
TableRef pk_table_ref;
/// \brief The foreign table (for which foreign key columns will be listed).
@@ -131,19 +131,19 @@ struct GetCrossReference {
};
/// \brief A request to create a new prepared statement.
-struct ActionCreatePreparedStatementRequest {
+struct ARROW_FLIGHT_EXPORT ActionCreatePreparedStatementRequest {
/// \brief The SQL query.
std::string query;
};
/// \brief A request to close a prepared statement.
-struct ActionClosePreparedStatementRequest {
+struct ARROW_FLIGHT_EXPORT ActionClosePreparedStatementRequest {
/// \brief The server-generated opaque identifier for the statement.
std::string prepared_statement_handle;
};
/// \brief The result of creating a new prepared statement.
-struct ActionCreatePreparedStatementResult {
+struct ARROW_FLIGHT_EXPORT ActionCreatePreparedStatementResult {
/// \brief The schema of the query results, if applicable.
std::shared_ptr dataset_schema;
/// \brief The schema of the query parameters, if applicable.
@@ -160,6 +160,7 @@ struct ActionCreatePreparedStatementResult {
///
/// \param[in] statement_handle The statement handle that will originate the ticket.
/// \return The parsed ticket as an string.
+ARROW_FLIGHT_EXPORT
arrow::Result CreateStatementQueryTicket(
const std::string& statement_handle);
@@ -167,7 +168,7 @@ arrow::Result CreateStatementQueryTicket(
///
/// Applications should subclass this class and override the virtual
/// methods declared on this class.
-class ARROW_EXPORT FlightSqlServerBase : public FlightServerBase {
+class ARROW_FLIGHT_EXPORT FlightSqlServerBase : public FlightServerBase {
private:
SqlInfoResultMap sql_info_id_to_result_;
@@ -488,7 +489,7 @@ class ARROW_EXPORT FlightSqlServerBase : public FlightServerBase {
};
/// \brief Auxiliary class containing all Schemas used on Flight SQL.
-class ARROW_EXPORT SqlSchema {
+class ARROW_FLIGHT_EXPORT SqlSchema {
public:
/// \brief Get the Schema used on GetCatalogs response.
/// \return The default schema template.
diff --git a/cpp/src/arrow/flight/sql/sql_info_internal.h b/cpp/src/arrow/flight/sql/sql_info_internal.h
index b18789c25498c..89328e4138866 100644
--- a/cpp/src/arrow/flight/sql/sql_info_internal.h
+++ b/cpp/src/arrow/flight/sql/sql_info_internal.h
@@ -18,6 +18,7 @@
#pragma once
#include "arrow/flight/sql/types.h"
+#include "arrow/flight/visibility.h"
namespace arrow {
namespace flight {
@@ -26,7 +27,7 @@ namespace internal {
/// \brief Auxiliary class used to populate GetSqlInfo's DenseUnionArray with different
/// data types.
-class SqlInfoResultAppender {
+class ARROW_FLIGHT_EXPORT SqlInfoResultAppender {
public:
/// \brief Append a string to the DenseUnionBuilder.
/// \param[in] value Value to be appended.
diff --git a/cpp/src/arrow/flight/sql/types.h b/cpp/src/arrow/flight/sql/types.h
index ebfb2ef0eaf18..7f81fea3cd068 100644
--- a/cpp/src/arrow/flight/sql/types.h
+++ b/cpp/src/arrow/flight/sql/types.h
@@ -22,6 +22,7 @@
#include
#include
+#include "arrow/flight/visibility.h"
#include "arrow/type_fwd.h"
#include "arrow/util/optional.h"
#include "arrow/util/variant.h"
@@ -43,7 +44,7 @@ using SqlInfoResult =
using SqlInfoResultMap = std::unordered_map;
/// \brief Options to be set in the SqlInfo.
-struct SqlInfoOptions {
+struct ARROW_FLIGHT_EXPORT SqlInfoOptions {
/// \brief Predefined info values for GetSqlInfo.
enum SqlInfo {
/// \name Server Information
@@ -835,7 +836,7 @@ struct SqlInfoOptions {
};
/// \brief A SQL %table reference, optionally containing table's catalog and db_schema.
-struct TableRef {
+struct ARROW_FLIGHT_EXPORT TableRef {
/// \brief The table's catalog.
util::optional catalog;
/// \brief The table's database schema.