diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 1d681c96a75..cbb56907410 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -281,6 +281,7 @@ jobs: ARROW_BUILD_TYPE: release ARROW_DATASET: ON ARROW_FLIGHT: ON + ARROW_FLIGHT_SQL: ON ARROW_GANDIVA: ON ARROW_GCS: ON ARROW_HDFS: OFF diff --git a/appveyor.yml b/appveyor.yml index 2699e479b79..03a3597c9b7 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 e9441c63e20..e7fea480b4f 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/cmake_modules/BuildUtils.cmake b/cpp/cmake_modules/BuildUtils.cmake index 5ce65ee51d0..888ca19af58 100644 --- a/cpp/cmake_modules/BuildUtils.cmake +++ b/cpp/cmake_modules/BuildUtils.cmake @@ -386,6 +386,7 @@ function(ADD_ARROW_LIB LIB_NAME) if(WIN32) target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_STATIC) target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_FLIGHT_STATIC) + target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_FLIGHT_SQL_STATIC) endif() set_target_properties(${LIB_NAME}_static diff --git a/cpp/src/arrow/flight/sql/CMakeLists.txt b/cpp/src/arrow/flight/sql/CMakeLists.txt index 1f5a72b50da..0c789fd71c5 100644 --- a/cpp/src/arrow/flight/sql/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/CMakeLists.txt @@ -29,11 +29,11 @@ set(PROTO_DEPENDS ${FLIGHT_SQL_PROTO} ${ARROW_PROTOBUF_LIBPROTOBUF}) add_custom_command(OUTPUT ${FLIGHT_SQL_GENERATED_PROTO_FILES} COMMAND ${ARROW_PROTOBUF_PROTOC} "-I${FLIGHT_SQL_PROTO_PATH}" - "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" "${FLIGHT_SQL_PROTO}" + "--cpp_out=dllexport_decl=ARROW_FLIGHT_SQL_EXPORT:${CMAKE_CURRENT_BINARY_DIR}" + "${FLIGHT_SQL_PROTO}" DEPENDS ${PROTO_DEPENDS}) set_source_files_properties(${FLIGHT_SQL_GENERATED_PROTO_FILES} PROPERTIES GENERATED TRUE) - add_custom_target(flight_sql_protobuf_gen ALL DEPENDS ${FLIGHT_SQL_GENERATED_PROTO_FILES}) set(ARROW_FLIGHT_SQL_SRCS @@ -41,7 +41,7 @@ set(ARROW_FLIGHT_SQL_SRCS sql_info_internal.cc column_metadata.cc client.cc - "${CMAKE_CURRENT_BINARY_DIR}/FlightSql.pb.cc") + protocol_internal.cc) add_arrow_lib(arrow_flight_sql CMAKE_PACKAGE_NAME @@ -63,6 +63,14 @@ add_arrow_lib(arrow_flight_sql PRIVATE_INCLUDES "${Protobuf_INCLUDE_DIRS}") +if(MSVC) + # Suppress warnings caused by Protobuf (casts) + set_source_files_properties(protocol_internal.cc PROPERTIES COMPILE_FLAGS "/wd4267") +endif() +foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_LIBRARIES}) + target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_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() @@ -81,11 +89,18 @@ if(ARROW_BUILD_TESTS OR ARROW_BUILD_EXAMPLES) example/sqlite_statement_batch_reader.cc example/sqlite_server.cc example/sqlite_tables_schema_batch_reader.cc) + set(ARROW_FLIGHT_SQL_TEST_SRCS server_test.cc) + if(NOT MSVC AND NOT MINGW) + # ARROW-16902: getting Protobuf generated code to have all the + # proper dllexport/dllimport declarations is difficult, since + # protoc does not insert them everywhere needed to satisfy both + # MinGW and MSVC, and the Protobuf team recommends against it + list(APPEND ARROW_FLIGHT_SQL_TEST_SRCS client_test.cc) + endif() add_arrow_test(flight_sql_test SOURCES - client_test.cc - server_test.cc + ${ARROW_FLIGHT_SQL_TEST_SRCS} ${ARROW_FLIGHT_SQL_TEST_SERVER_SRCS} STATIC_LINK_LIBS ${ARROW_FLIGHT_SQL_TEST_LINK_LIBS} @@ -102,4 +117,10 @@ if(ARROW_BUILD_TESTS OR ARROW_BUILD_EXAMPLES) add_executable(flight-sql-test-app test_app_cli.cc) target_link_libraries(flight-sql-test-app PRIVATE ${ARROW_FLIGHT_SQL_TEST_LINK_LIBS} ${GFLAGS_LIBRARIES}) + + if(ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static" AND ARROW_BUILD_STATIC) + target_compile_definitions(flight_sql_test + flight-sql-test-server flight-sql-test-app + PUBLIC ARROW_FLIGHT_STATIC ARROW_FLIGHT_SQL_STATIC) + endif() endif() diff --git a/cpp/src/arrow/flight/sql/client.cc b/cpp/src/arrow/flight/sql/client.cc index 89cfb3aad03..10ff1eea6f4 100644 --- a/cpp/src/arrow/flight/sql/client.cc +++ b/cpp/src/arrow/flight/sql/client.cc @@ -15,12 +15,15 @@ // specific language governing permissions and limitations // under the License. +// Platform-specific defines +#include "arrow/flight/platform.h" + #include "arrow/flight/sql/client.h" #include #include "arrow/buffer.h" -#include "arrow/flight/sql/FlightSql.pb.h" +#include "arrow/flight/sql/protocol_internal.h" #include "arrow/flight/types.h" #include "arrow/io/memory.h" #include "arrow/ipc/reader.h" diff --git a/cpp/src/arrow/flight/sql/client.h b/cpp/src/arrow/flight/sql/client.h index 78c162e4cda..7c8cb640e8d 100644 --- a/cpp/src/arrow/flight/sql/client.h +++ b/cpp/src/arrow/flight/sql/client.h @@ -22,6 +22,7 @@ #include "arrow/flight/client.h" #include "arrow/flight/sql/types.h" +#include "arrow/flight/sql/visibility.h" #include "arrow/flight/types.h" #include "arrow/result.h" #include "arrow/status.h" @@ -35,7 +36,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_SQL_EXPORT FlightSqlClient { friend class PreparedStatement; private: @@ -202,7 +203,7 @@ class ARROW_EXPORT FlightSqlClient { }; /// \brief A prepared statement that can be executed. -class ARROW_EXPORT PreparedStatement { +class ARROW_FLIGHT_SQL_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 1cfce2520f5..b9eeda76b00 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 @@ -24,8 +27,8 @@ #include #include "arrow/buffer.h" -#include "arrow/flight/sql/FlightSql.pb.h" #include "arrow/flight/sql/api.h" +#include "arrow/flight/sql/protocol_internal.h" #include "arrow/testing/gtest_util.h" namespace pb = arrow::flight::protocol; diff --git a/cpp/src/arrow/flight/sql/column_metadata.h b/cpp/src/arrow/flight/sql/column_metadata.h index 08e7c64aeec..15b139ec580 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/sql/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_SQL_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_SQL_EXPORT ColumnMetadataBuilder { public: friend class ColumnMetadata; diff --git a/cpp/src/arrow/flight/sql/example/sqlite_server.cc b/cpp/src/arrow/flight/sql/example/sqlite_server.cc index 2105eb5be03..35fa05468ba 100644 --- a/cpp/src/arrow/flight/sql/example/sqlite_server.cc +++ b/cpp/src/arrow/flight/sql/example/sqlite_server.cc @@ -249,9 +249,11 @@ class SQLiteFlightSqlServer::Impl { std::string GenerateRandomString() { uint32_t length = 16; - std::uniform_int_distribution dist('0', 'z'); + // MSVC doesn't support char types here + std::uniform_int_distribution dist(static_cast('0'), + static_cast('z')); std::string ret(length, 0); - auto get_random_char = [&]() { return dist(gen_); }; + auto get_random_char = [&]() { return static_cast(dist(gen_)); }; std::generate_n(ret.begin(), length, get_random_char); return ret; } @@ -384,14 +386,14 @@ class SQLiteFlightSqlServer::Impl { const ActionCreatePreparedStatementRequest& request) { std::shared_ptr statement; ARROW_ASSIGN_OR_RAISE(statement, SqliteStatement::Create(db_, request.query)); - const std::string handle = GenerateRandomString(); + std::string handle = GenerateRandomString(); prepared_statements_[handle] = statement; ARROW_ASSIGN_OR_RAISE(auto dataset_schema, statement->GetSchema()); sqlite3_stmt* stmt = statement->GetSqlite3Stmt(); const int parameter_count = sqlite3_bind_parameter_count(stmt); - std::vector> parameter_fields; + FieldVector parameter_fields; parameter_fields.reserve(parameter_count); // As SQLite doesn't know the parameter types before executing the query, the @@ -410,13 +412,9 @@ class SQLiteFlightSqlServer::Impl { parameter_fields.push_back(field(parameter_name, dense_union_type)); } - const std::shared_ptr& parameter_schema = arrow::schema(parameter_fields); - - ActionCreatePreparedStatementResult result{.dataset_schema = dataset_schema, - .parameter_schema = parameter_schema, - .prepared_statement_handle = handle}; - - return result; + std::shared_ptr parameter_schema = arrow::schema(parameter_fields); + return ActionCreatePreparedStatementResult{ + std::move(dataset_schema), std::move(parameter_schema), std::move(handle)}; } Status ClosePreparedStatement(const ServerCallContext& context, diff --git a/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc b/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc index e31d6173ee8..c247eb62875 100644 --- a/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc +++ b/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc @@ -63,16 +63,17 @@ break; \ } -#define FLOAT_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \ - case TYPE_CLASS##Type::type_id: { \ - auto builder = reinterpret_cast(array_builder); \ - if (sqlite3_column_type(stmt_, i) == SQLITE_NULL) { \ - ARROW_RETURN_NOT_OK(builder->AppendNull()); \ - break; \ - } \ - const double value = sqlite3_column_double(STMT, COLUMN); \ - ARROW_RETURN_NOT_OK(builder->Append(value)); \ - break; \ +#define FLOAT_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \ + case TYPE_CLASS##Type::type_id: { \ + auto builder = reinterpret_cast(array_builder); \ + if (sqlite3_column_type(stmt_, i) == SQLITE_NULL) { \ + ARROW_RETURN_NOT_OK(builder->AppendNull()); \ + break; \ + } \ + const double value = sqlite3_column_double(STMT, COLUMN); \ + ARROW_RETURN_NOT_OK( \ + builder->Append(static_cast(value))); \ + break; \ } namespace arrow { diff --git a/cpp/src/arrow/flight/sql/protocol_internal.cc b/cpp/src/arrow/flight/sql/protocol_internal.cc new file mode 100644 index 00000000000..0d5e3c4c60b --- /dev/null +++ b/cpp/src/arrow/flight/sql/protocol_internal.cc @@ -0,0 +1,23 @@ +// 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 + +#include "arrow/flight/sql/protocol_internal.h" + +// NOTE(lidavidm): Normally this is forbidden, but on Windows to get +// the dllexport/dllimport macro in the right places, we need to +// ensure our header gets included (and Protobuf will not insert the +// include for you) +#include "arrow/flight/sql/FlightSql.pb.cc" // NOLINT diff --git a/cpp/src/arrow/flight/sql/protocol_internal.h b/cpp/src/arrow/flight/sql/protocol_internal.h new file mode 100644 index 00000000000..ce50ad2f61b --- /dev/null +++ b/cpp/src/arrow/flight/sql/protocol_internal.h @@ -0,0 +1,26 @@ +// 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 + +#pragma once + +// This addresses platform-specific defines, e.g. on Windows +#include "arrow/flight/platform.h" // IWYU pragma: keep + +// This header holds the Flight SQL definitions. + +#include "arrow/flight/sql/visibility.h" + +#include "arrow/flight/sql/FlightSql.pb.h" // IWYU pragma: export diff --git a/cpp/src/arrow/flight/sql/server.cc b/cpp/src/arrow/flight/sql/server.cc index 5ad1be466e1..0ebe647ba14 100644 --- a/cpp/src/arrow/flight/sql/server.cc +++ b/cpp/src/arrow/flight/sql/server.cc @@ -18,13 +18,16 @@ // 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 #include "arrow/buffer.h" #include "arrow/builder.h" -#include "arrow/flight/sql/FlightSql.pb.h" +#include "arrow/flight/sql/protocol_internal.h" #include "arrow/flight/sql/sql_info_internal.h" #include "arrow/type.h" #include "arrow/util/checked_cast.h" diff --git a/cpp/src/arrow/flight/sql/server.h b/cpp/src/arrow/flight/sql/server.h index 4e6ddce2397..f077c5d5d5d 100644 --- a/cpp/src/arrow/flight/sql/server.h +++ b/cpp/src/arrow/flight/sql/server.h @@ -27,6 +27,7 @@ #include "arrow/flight/server.h" #include "arrow/flight/sql/server.h" #include "arrow/flight/sql/types.h" +#include "arrow/flight/sql/visibility.h" #include "arrow/util/optional.h" namespace arrow { @@ -39,43 +40,43 @@ namespace sql { /// @{ /// \brief A SQL query. -struct StatementQuery { +struct ARROW_FLIGHT_SQL_EXPORT StatementQuery { /// \brief The SQL query. std::string query; }; /// \brief A SQL update query. -struct StatementUpdate { +struct ARROW_FLIGHT_SQL_EXPORT StatementUpdate { /// \brief The SQL query. std::string query; }; /// \brief A request to execute a query. -struct StatementQueryTicket { +struct ARROW_FLIGHT_SQL_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_SQL_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_SQL_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_SQL_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_SQL_EXPORT GetDbSchemas { /// \brief An optional database catalog to filter on. util::optional catalog; /// \brief An optional database schema to filter on. @@ -83,7 +84,7 @@ struct GetDbSchemas { }; /// \brief A request to list database tables. -struct GetTables { +struct ARROW_FLIGHT_SQL_EXPORT GetTables { /// \brief An optional database catalog to filter on. util::optional catalog; /// \brief An optional database schema to filter on. @@ -97,33 +98,33 @@ struct GetTables { }; /// \brief A request to get SQL data type information. -struct GetXdbcTypeInfo { +struct ARROW_FLIGHT_SQL_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_SQL_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_SQL_EXPORT GetExportedKeys { /// \brief The given table. TableRef table_ref; }; /// \brief A request to list foreign keys of a table. -struct GetImportedKeys { +struct ARROW_FLIGHT_SQL_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_SQL_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 +132,19 @@ struct GetCrossReference { }; /// \brief A request to create a new prepared statement. -struct ActionCreatePreparedStatementRequest { +struct ARROW_FLIGHT_SQL_EXPORT ActionCreatePreparedStatementRequest { /// \brief The SQL query. std::string query; }; /// \brief A request to close a prepared statement. -struct ActionClosePreparedStatementRequest { +struct ARROW_FLIGHT_SQL_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_SQL_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 +161,7 @@ struct ActionCreatePreparedStatementResult { /// /// \param[in] statement_handle The statement handle that will originate the ticket. /// \return The parsed ticket as an string. +ARROW_FLIGHT_SQL_EXPORT arrow::Result CreateStatementQueryTicket( const std::string& statement_handle); @@ -167,7 +169,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_SQL_EXPORT FlightSqlServerBase : public FlightServerBase { private: SqlInfoResultMap sql_info_id_to_result_; @@ -488,7 +490,7 @@ class ARROW_EXPORT FlightSqlServerBase : public FlightServerBase { }; /// \brief Auxiliary class containing all Schemas used on Flight SQL. -class ARROW_EXPORT SqlSchema { +class ARROW_FLIGHT_SQL_EXPORT SqlSchema { public: /// \brief Get the Schema used on GetCatalogs response. /// \return The default schema template. diff --git a/cpp/src/arrow/flight/sql/server_test.cc b/cpp/src/arrow/flight/sql/server_test.cc index 746c91c102b..69081acdb59 100644 --- a/cpp/src/arrow/flight/sql/server_test.cc +++ b/cpp/src/arrow/flight/sql/server_test.cc @@ -21,6 +21,7 @@ #include #include +#include #include #include diff --git a/cpp/src/arrow/flight/sql/sql_info_internal.h b/cpp/src/arrow/flight/sql/sql_info_internal.h index b18789c2549..2a3cafdbe61 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/sql/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_SQL_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 ebfb2ef0eaf..a6c2648e7c4 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/sql/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_SQL_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_SQL_EXPORT TableRef { /// \brief The table's catalog. util::optional catalog; /// \brief The table's database schema. diff --git a/cpp/src/arrow/flight/sql/visibility.h b/cpp/src/arrow/flight/sql/visibility.h new file mode 100644 index 00000000000..2074815e0a2 --- /dev/null +++ b/cpp/src/arrow/flight/sql/visibility.h @@ -0,0 +1,48 @@ +// 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 + +#if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4251) +#else +#pragma GCC diagnostic ignored "-Wattributes" +#endif + +#ifdef ARROW_FLIGHT_SQL_STATIC +#define ARROW_FLIGHT_SQL_EXPORT +#elif defined(ARROW_FLIGHT_SQL_EXPORTING) +#define ARROW_FLIGHT_SQL_EXPORT __declspec(dllexport) +#else +#define ARROW_FLIGHT_SQL_EXPORT __declspec(dllimport) +#endif + +#define ARROW_FLIGHT_SQL_NO_EXPORT +#else // Not Windows +#ifndef ARROW_FLIGHT_SQL_EXPORT +#define ARROW_FLIGHT_SQL_EXPORT __attribute__((visibility("default"))) +#endif +#ifndef ARROW_FLIGHT_SQL_NO_EXPORT +#define ARROW_FLIGHT_SQL_NO_EXPORT __attribute__((visibility("hidden"))) +#endif +#endif // Non-Windows + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif diff --git a/cpp/src/arrow/symbols.map b/cpp/src/arrow/symbols.map index 0c5616c692d..7d4f13fa286 100644 --- a/cpp/src/arrow/symbols.map +++ b/cpp/src/arrow/symbols.map @@ -35,6 +35,7 @@ pyarrow_*; # ARROW-14771: export Protobuf symbol table descriptor_table_Flight_2eproto; + descriptor_table_FlightSql_2eproto; # Symbols marked as 'local' are not exported by the DSO and thus may not # be used by client applications. Everything except the above falls here. diff --git a/docs/source/developers/cpp/windows.rst b/docs/source/developers/cpp/windows.rst index 84ba000cb58..91562a2c8cb 100644 --- a/docs/source/developers/cpp/windows.rst +++ b/docs/source/developers/cpp/windows.rst @@ -363,7 +363,7 @@ against Arrow on Windows additionally need this definition. The Unix builds do not use the macro. In addition if using ``-DARROW_FLIGHT=ON``, ``ARROW_FLIGHT_STATIC`` needs to -be defined. +be defined, and similarly for ``-DARROW_FLIGHT_SQL=ON``. .. code-block:: cmake @@ -372,9 +372,17 @@ be defined. find_package(Arrow REQUIRED) add_executable(my_example my_example.cc) - target_link_libraries(my_example PRIVATE arrow_static arrow_flight_static) - - target_compile_definitions(my_example PUBLIC ARROW_STATIC ARROW_FLIGHT_STATIC) + target_link_libraries(my_example + PRIVATE + arrow_static + arrow_flight_static + arrow_flight_sql_static) + + target_compile_definitions(my_example + PUBLIC + ARROW_STATIC + ARROW_FLIGHT_STATIC + ARROW_FLIGHT_SQL_STATIC) Downloading the Timezone Database =================================