Skip to content

Commit

Permalink
Introduce ARROW_FLIGHT_SQL_EXPORT
Browse files Browse the repository at this point in the history
  • Loading branch information
lidavidm committed Jun 27, 2022
1 parent bd0b134 commit e5cadd1
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 34 deletions.
1 change: 1 addition & 0 deletions cpp/cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,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
Expand Down
8 changes: 7 additions & 1 deletion cpp/src/arrow/flight/sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ add_arrow_lib(arrow_flight_sql
"${Protobuf_INCLUDE_DIRS}")

foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_LIBRARIES})
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_EXPORTING)
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_EXPORTING)
endforeach()

if(ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static" AND ARROW_BUILD_STATIC)
Expand Down Expand Up @@ -111,4 +111,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()
5 changes: 3 additions & 2 deletions cpp/src/arrow/flight/sql/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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_FLIGHT_EXPORT FlightSqlClient {
class ARROW_FLIGHT_SQL_EXPORT FlightSqlClient {
friend class PreparedStatement;

private:
Expand Down Expand Up @@ -202,7 +203,7 @@ class ARROW_FLIGHT_EXPORT FlightSqlClient {
};

/// \brief A prepared statement that can be executed.
class ARROW_FLIGHT_EXPORT PreparedStatement {
class ARROW_FLIGHT_SQL_EXPORT PreparedStatement {
public:
/// \brief Create a new prepared statement. However, applications
/// should generally use FlightSqlClient::Prepare.
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/flight/sql/column_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

#include <string>

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

namespace arrow {
namespace flight {
namespace sql {

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

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

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

Expand Down
39 changes: 20 additions & 19 deletions cpp/src/arrow/flight/sql/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -39,51 +40,51 @@ namespace sql {
/// @{

/// \brief A SQL query.
struct ARROW_FLIGHT_EXPORT StatementQuery {
struct ARROW_FLIGHT_SQL_EXPORT StatementQuery {
/// \brief The SQL query.
std::string query;
};

/// \brief A SQL update query.
struct ARROW_FLIGHT_EXPORT StatementUpdate {
struct ARROW_FLIGHT_SQL_EXPORT StatementUpdate {
/// \brief The SQL query.
std::string query;
};

/// \brief A request to execute a query.
struct ARROW_FLIGHT_EXPORT 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 ARROW_FLIGHT_EXPORT 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 ARROW_FLIGHT_EXPORT 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 ARROW_FLIGHT_EXPORT GetSqlInfo {
struct ARROW_FLIGHT_SQL_EXPORT GetSqlInfo {
/// \brief A list of metadata IDs to fetch.
std::vector<int32_t> info;
};

/// \brief A request to list database schemas.
struct ARROW_FLIGHT_EXPORT GetDbSchemas {
struct ARROW_FLIGHT_SQL_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 ARROW_FLIGHT_EXPORT GetTables {
struct ARROW_FLIGHT_SQL_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 +98,53 @@ struct ARROW_FLIGHT_EXPORT GetTables {
};

/// \brief A request to get SQL data type information.
struct ARROW_FLIGHT_EXPORT GetXdbcTypeInfo {
struct ARROW_FLIGHT_SQL_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 ARROW_FLIGHT_EXPORT 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 ARROW_FLIGHT_EXPORT 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 ARROW_FLIGHT_EXPORT 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 ARROW_FLIGHT_EXPORT 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).
TableRef fk_table_ref;
};

/// \brief A request to create a new prepared statement.
struct ARROW_FLIGHT_EXPORT ActionCreatePreparedStatementRequest {
struct ARROW_FLIGHT_SQL_EXPORT ActionCreatePreparedStatementRequest {
/// \brief The SQL query.
std::string query;
};

/// \brief A request to close a prepared statement.
struct ARROW_FLIGHT_EXPORT 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 ARROW_FLIGHT_EXPORT ActionCreatePreparedStatementResult {
struct ARROW_FLIGHT_SQL_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,15 +161,15 @@ struct ARROW_FLIGHT_EXPORT ActionCreatePreparedStatementResult {
///
/// \param[in] statement_handle The statement handle that will originate the ticket.
/// \return The parsed ticket as an string.
ARROW_FLIGHT_EXPORT
ARROW_FLIGHT_SQL_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_FLIGHT_EXPORT FlightSqlServerBase : public FlightServerBase {
class ARROW_FLIGHT_SQL_EXPORT FlightSqlServerBase : public FlightServerBase {
private:
SqlInfoResultMap sql_info_id_to_result_;

Expand Down Expand Up @@ -489,7 +490,7 @@ class ARROW_FLIGHT_EXPORT FlightSqlServerBase : public FlightServerBase {
};

/// \brief Auxiliary class containing all Schemas used on Flight SQL.
class ARROW_FLIGHT_EXPORT SqlSchema {
class ARROW_FLIGHT_SQL_EXPORT SqlSchema {
public:
/// \brief Get the Schema used on GetCatalogs response.
/// \return The default schema template.
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/flight/sql/sql_info_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#pragma once

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

namespace arrow {
namespace flight {
Expand All @@ -27,7 +27,7 @@ namespace internal {

/// \brief Auxiliary class used to populate GetSqlInfo's DenseUnionArray with different
/// data types.
class ARROW_FLIGHT_EXPORT SqlInfoResultAppender {
class ARROW_FLIGHT_SQL_EXPORT SqlInfoResultAppender {
public:
/// \brief Append a string to the DenseUnionBuilder.
/// \param[in] value Value to be appended.
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/flight/sql/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <unordered_map>
#include <vector>

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

/// \brief Options to be set in the SqlInfo.
struct ARROW_FLIGHT_EXPORT SqlInfoOptions {
struct ARROW_FLIGHT_SQL_EXPORT SqlInfoOptions {
/// \brief Predefined info values for GetSqlInfo.
enum SqlInfo {
/// \name Server Information
Expand Down Expand Up @@ -836,7 +836,7 @@ struct ARROW_FLIGHT_EXPORT SqlInfoOptions {
};

/// \brief A SQL %table reference, optionally containing table's catalog and db_schema.
struct ARROW_FLIGHT_EXPORT TableRef {
struct ARROW_FLIGHT_SQL_EXPORT TableRef {
/// \brief The table's catalog.
util::optional<std::string> catalog;
/// \brief The table's database schema.
Expand Down
48 changes: 48 additions & 0 deletions cpp/src/arrow/flight/sql/visibility.h
Original file line number Diff line number Diff line change
@@ -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
16 changes: 12 additions & 4 deletions docs/source/developers/cpp/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
=================================
Expand Down

0 comments on commit e5cadd1

Please sign in to comment.