Skip to content

Commit fde5c00

Browse files
[C++] Implements methods from flight-sql-client (apache#120)
* add a header file to the sql-client * Implements methods from sql-client * Add configuration files to the flight-sql * Change getFlightInfo to virtual and its constructor to protected * Create a mock test for getCatalogs * Remove unused test from CMakeLists.txt * Fix checkstyle on flight-sql files * Fix duplicate tests execution * Add test for getSchema from flightsql * Update flight headers and implements getTable and getTableTypes * Add other unit tests for metadata methods * Fix checkstyle errors * Implement missing methods GetPrimaryKeys, GetImportedKeys and GetExportedKeys * Refactor flight-sql/client.cc implementation * Remove unimplemented ExecuteUpdate test * Add google/protobuf/message include to flight-sql-client * Undo changes on flight/client.h and use templates for mocking FlightClient on FlightSqlClient * Use string references where parameters can not be null * Reorder FlightSqlClient method arguments * Avoid needing to use diamond syntax on FlightSqlClient Co-authored-by: Rafael Telles <rafael@telles.dev>
1 parent f3fe962 commit fde5c00

File tree

6 files changed

+592
-14
lines changed

6 files changed

+592
-14
lines changed

cpp/src/arrow/flight/flight-sql/CMakeLists.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ add_custom_target(arrow_flight_sql)
1919

2020
arrow_install_all_headers("arrow/flight/flight-sql")
2121

22+
set(ARROW_FLIGHT_SQL_LINK_LIBS ${ARROW_PROTOBUF_LIBPROTOBUF})
23+
2224
set(FLIGHT_SQL_PROTO_PATH "${ARROW_SOURCE_DIR}/../format")
2325
set(FLIGHT_SQL_PROTO ${ARROW_SOURCE_DIR}/../format/FlightSql.proto)
2426

@@ -49,7 +51,7 @@ set(CMAKE_CXX_FLAGS_BACKUP "${CMAKE_CXX_FLAGS}")
4951
string(REPLACE "/WX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
5052
string(REPLACE "-Werror " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
5153

52-
set(ARROW_FLIGHT_SQL_SRCS client.cc)
54+
set(ARROW_FLIGHT_SQL_SRCS protocol_internal.cc)
5355

5456
add_arrow_lib(arrow_flight_sql
5557
CMAKE_PACKAGE_NAME
@@ -61,20 +63,31 @@ add_arrow_lib(arrow_flight_sql
6163
SOURCES
6264
${ARROW_FLIGHT_SQL_SRCS}
6365
PRECOMPILED_HEADERS
64-
"$<$<COMPILE_LANGUAGE:CXX>:arrow/flight/pch.h>"
66+
"$<$<COMPILE_LANGUAGE:CXX>:arrow/flight/flight-sql/pch.h>"
6567
DEPENDENCIES
6668
flight_sql_grpc_gen
6769
SHARED_LINK_FLAGS
6870
${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
6971
SHARED_LINK_LIBS
70-
arrow_shared
71-
${ARROW_FLIGHT_LINK_LIBS}
72+
arrow_flight_shared
73+
${ARROW_FLIGHT_SQL_LINK_LIBS}
7274
STATIC_LINK_LIBS
73-
arrow_static
74-
${ARROW_FLIGHT_LINK_LIBS})
75+
arrow_flight_static
76+
${ARROW_FLIGHT_SQL_LINK_LIBS})
77+
78+
if(ARROW_TEST_LINKAGE STREQUAL "static")
79+
set(ARROW_FLIGHT_SQL_TEST_LINK_LIBS
80+
arrow_flight_sql_static ${ARROW_FLIGHT_STATIC_LINK_LIBS} ${ARROW_TEST_LINK_LIBS})
81+
else()
82+
set(ARROW_FLIGHT_SQL_TEST_LINK_LIBS arrow_flight_sql_shared ${ARROW_TEST_LINK_LIBS})
83+
endif()
7584

7685
add_arrow_test(flight_sql_test
7786
SOURCES
7887
client_test.cc
88+
STATIC_LINK_LIBS
89+
${ARROW_FLIGHT_SQL_TEST_LINK_LIBS}
90+
GTest::gtest
91+
GTest::gmock
7992
LABELS
8093
"arrow_flight_sql")

cpp/src/arrow/flight/flight-sql/client.h

Lines changed: 143 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,150 @@
1818
#ifndef ARROW_FLIGHT_SQL_CLIENT_H
1919
#define ARROW_FLIGHT_SQL_CLIENT_H
2020

21+
#include <arrow/flight/client.h>
22+
#include <arrow/flight/types.h>
23+
#include <arrow/status.h>
24+
#include <google/protobuf/message.h>
2125

22-
class client {
26+
namespace arrow {
27+
namespace flight {
28+
namespace sql {
29+
namespace internal {
30+
31+
/// \brief Flight client with Flight SQL semantics.
32+
template <class T = arrow::flight::FlightClient>
33+
class FlightSqlClientT {
34+
public:
35+
explicit FlightSqlClientT(T* client);
36+
37+
~FlightSqlClientT();
38+
39+
/// \brief Execute a query on the server.
40+
/// \param[in] options RPC-layer hints for this call.
41+
/// \param[out] flight_info The FlightInfo describing where to access the dataset
42+
/// \param[in] query The query to be executed in the UTF-8 format.
43+
/// \return Status.
44+
Status Execute(const FlightCallOptions& options,
45+
std::unique_ptr<FlightInfo>* flight_info,
46+
const std::string& query);
47+
48+
/// \brief Execute an update query on the server.
49+
/// \param[in] options RPC-layer hints for this call.
50+
/// \param[out] rows The quantity of rows affected by the operation.
51+
/// \param[in] query The query to be executed in the UTF-8 format.
52+
/// \return Status.
53+
Status ExecuteUpdate(const FlightCallOptions& options,
54+
int64_t* rows,
55+
const std::string& query);
56+
57+
/// \brief Request a list of catalogs.
58+
/// \param[in] options RPC-layer hints for this call.
59+
/// \param[out] flight_info The FlightInfo describing where to access the dataset.
60+
/// \return Status.
61+
Status GetCatalogs(const FlightCallOptions& options,
62+
std::unique_ptr<FlightInfo>* flight_info);
63+
64+
/// \brief Request a list of schemas.
65+
/// \param[in] options RPC-layer hints for this call.
66+
/// \param[out] flight_info The FlightInfo describing where to access the
67+
/// dataset.
68+
/// \param[in] catalog The catalog.
69+
/// \param[in] schema_filter_pattern The schema filter pattern.
70+
/// \return Status.
71+
Status GetSchemas(const FlightCallOptions& options,
72+
std::unique_ptr<FlightInfo>* flight_info,
73+
std::string* catalog,
74+
std::string* schema_filter_pattern);
75+
76+
/// \brief Given a flight ticket and schema, request to be sent the
77+
/// stream. Returns record batch stream reader
78+
/// \param[in] options Per-RPC options
79+
/// \param[in] ticket The flight ticket to use
80+
/// \param[out] stream the returned RecordBatchReader
81+
/// \return Status
82+
Status DoGet(const FlightCallOptions& options,
83+
const Ticket& ticket,
84+
std::unique_ptr<FlightStreamReader>* stream);
85+
86+
/// \brief Request a list of tables.
87+
/// \param[in] options RPC-layer hints for this call.
88+
/// \param[out] flight_info The FlightInfo describing where to access the
89+
/// dataset.
90+
/// \param[in] catalog The catalog.
91+
/// \param[in] schema_filter_pattern The schema filter pattern.
92+
/// \param[in] table_filter_pattern The table filter pattern.
93+
/// \param[in] include_schema True to include the schema upon return,
94+
/// false to not include the schema.
95+
/// \param[in] table_types The table types to include.
96+
/// \return Status.
97+
Status GetTables(const FlightCallOptions& options,
98+
std::unique_ptr<FlightInfo>* flight_info,
99+
const std::string* catalog,
100+
const std::string* schema_filter_pattern,
101+
const std::string* table_filter_pattern,
102+
bool include_schema,
103+
std::vector<std::string>& table_types);
104+
105+
/// \brief Request the primary keys for a table.
106+
/// \param[in] options RPC-layer hints for this call.
107+
/// \param[out] flight_info The FlightInfo describing where to access the dataset.
108+
/// \param[in] catalog The catalog.
109+
/// \param[in] schema The schema.
110+
/// \param[in] table The table.
111+
/// \return Status.
112+
Status GetPrimaryKeys(const FlightCallOptions& options,
113+
std::unique_ptr<FlightInfo>* flight_info,
114+
const std::string* catalog,
115+
const std::string* schema,
116+
const std::string& table);
117+
118+
/// \brief Retrieves a description about the foreign key columns that reference the
119+
/// primary key columns of the given table.
120+
/// \param[in] options RPC-layer hints for this call.
121+
/// \param[out] flight_info The FlightInfo describing where to access the dataset.
122+
/// \param[in] catalog The foreign key table catalog.
123+
/// \param[in] schema The foreign key table schema.
124+
/// \param[in] table The foreign key table. Cannot be null.
125+
/// \return Status.
126+
Status GetExportedKeys(const FlightCallOptions& options,
127+
std::unique_ptr<FlightInfo>* flight_info,
128+
const std::string* catalog,
129+
const std::string* schema,
130+
const std::string& table);
131+
132+
/// \brief Retrieves the foreign key columns for the given table.
133+
/// \param[in] options RPC-layer hints for this call.
134+
/// \param[out] flight_info The FlightInfo describing where to access the dataset.
135+
/// \param[in] catalog The primary key table catalog.
136+
/// \param[in] schema The primary key table schema.
137+
/// \param[in] table The primary key table. Cannot be null.
138+
/// \return Status.
139+
Status GetImportedKeys(const FlightCallOptions& options,
140+
std::unique_ptr<FlightInfo>* flight_info,
141+
const std::string* catalog,
142+
const std::string* schema,
143+
const std::string& table);
144+
145+
/// \brief Request a list of table types.
146+
/// \param[in] options RPC-layer hints for this call.
147+
/// \param[out] flight_info The FlightInfo describing where to access the dataset.
148+
/// \return Status.
149+
Status GetTableTypes(const FlightCallOptions& options,
150+
std::unique_ptr<FlightInfo>* flight_info);
151+
152+
153+
private:
154+
T* client;
23155
};
24156

157+
} // namespace internal
158+
159+
typedef internal::FlightSqlClientT<FlightClient> FlightSqlClient;
160+
161+
} // namespace sql
162+
} // namespace flight
163+
} // namespace arrow
164+
165+
#endif // ARROW_FLIGHT_SQL_CLIENT_H
25166

26-
#endif //ARROW_FLIGHT_SQL_CLIENT_H
167+
#include <arrow/flight/flight-sql/client_impl.h>

0 commit comments

Comments
 (0)