Skip to content

Commit

Permalink
ARROW-16902: [C++][FlightRPC] Fix DLL linkage in Flight SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
lidavidm committed Jun 24, 2022
1 parent 5609b86 commit 6d38848
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions ci/appveyor-cpp-build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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 ^
Expand Down
9 changes: 9 additions & 0 deletions cpp/src/arrow/flight/sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/flight/sql/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <google/protobuf/any.pb.h>
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/flight/sql/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/flight/sql/client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gmock/gmock.h>
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/flight/sql/column_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

#include <string>

#include "arrow/flight/visibility.h"
#include "arrow/util/key_value_metadata.h"

namespace arrow {
namespace flight {
namespace sql {

/// \brief Helper class to set column metadata.
class ColumnMetadata {
class ARROW_FLIGHT_EXPORT ColumnMetadata {
private:
std::shared_ptr<const arrow::KeyValueMetadata> metadata_map_;

Expand Down Expand Up @@ -114,7 +115,7 @@ class ColumnMetadata {
const std::shared_ptr<const arrow::KeyValueMetadata>& metadata_map() const;

/// \brief A builder class to construct the ColumnMetadata object.
class ColumnMetadataBuilder {
class ARROW_FLIGHT_EXPORT ColumnMetadataBuilder {
public:
friend class ColumnMetadata;

Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/flight/sql/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <google/protobuf/any.pb.h>
Expand Down
37 changes: 19 additions & 18 deletions cpp/src/arrow/flight/sql/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,51 +39,51 @@ 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<int32_t> 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<std::string> catalog;
/// \brief An optional database schema to filter on.
util::optional<std::string> db_schema_filter_pattern;
};

/// \brief A request to list database tables.
struct GetTables {
struct ARROW_FLIGHT_EXPORT GetTables {
/// \brief An optional database catalog to filter on.
util::optional<std::string> catalog;
/// \brief An optional database schema to filter on.
Expand All @@ -97,53 +97,53 @@ 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<int> 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).
TableRef fk_table_ref;
};

/// \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<Schema> dataset_schema;
/// \brief The schema of the query parameters, if applicable.
Expand All @@ -160,14 +160,15 @@ 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<std::string> CreateStatementQueryTicket(
const std::string& statement_handle);

/// \brief The base class for Flight SQL servers.
///
/// 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_;

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/flight/sql/sql_info_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include "arrow/flight/sql/types.h"
#include "arrow/flight/visibility.h"

namespace arrow {
namespace flight {
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/flight/sql/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <unordered_map>
#include <vector>

#include "arrow/flight/visibility.h"
#include "arrow/type_fwd.h"
#include "arrow/util/optional.h"
#include "arrow/util/variant.h"
Expand All @@ -43,7 +44,7 @@ using SqlInfoResult =
using SqlInfoResultMap = std::unordered_map<int32_t, SqlInfoResult>;

/// \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
Expand Down Expand Up @@ -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<std::string> catalog;
/// \brief The table's database schema.
Expand Down

0 comments on commit 6d38848

Please sign in to comment.