Skip to content

Commit 053c313

Browse files
authored
Replace boost::optional with std::optional
Addresses comment apache#40939 (comment) Replace boost::optional with std::optional in ODBC codebase
1 parent cefac6c commit 053c313

15 files changed

+74
-56
lines changed

cpp/src/arrow/flight/sql/odbc/odbc_impl/blocking_queue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#pragma once
1919

2020
#include <atomic>
21-
#include <boost/optional.hpp>
2221
#include <condition_variable>
2322
#include <mutex>
23+
#include <optional>
2424
#include <thread>
2525
#include <vector>
2626

@@ -43,7 +43,7 @@ class BlockingQueue {
4343
std::atomic<bool> closed_{false};
4444

4545
public:
46-
typedef std::function<boost::optional<T>(void)> Supplier;
46+
typedef std::function<std::optional<T>(void)> Supplier;
4747

4848
explicit BlockingQueue(size_t capacity) : capacity_(capacity), buffer_(capacity) {}
4949

@@ -58,7 +58,7 @@ class BlockingQueue {
5858

5959
// Only one thread at a time be notified and call supplier
6060
auto item = supplier();
61-
if (!item) break;
61+
if (!item.has_value()) break;
6262

6363
Push(*item);
6464
}

cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_auth_method.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "arrow/result.h"
2525
#include "arrow/status.h"
2626

27+
#include <optional>
2728
#include <utility>
2829

2930
namespace arrow::flight::sql::odbc {
@@ -74,7 +75,7 @@ class UserPasswordAuthMethod : public FlightSqlAuthMethod {
7475
void Authenticate(FlightSqlConnection& connection,
7576
FlightCallOptions& call_options) override {
7677
FlightCallOptions auth_call_options;
77-
const boost::optional<Connection::Attribute>& login_timeout =
78+
const std::optional<Connection::Attribute>& login_timeout =
7879
connection.GetAttribute(Connection::LOGIN_TIMEOUT);
7980
if (login_timeout && boost::get<uint32_t>(*login_timeout) > 0) {
8081
// ODBC's LOGIN_TIMEOUT attribute and FlightCallOptions.timeout use

cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <boost/algorithm/string/join.hpp>
3232
#include <boost/asio/ip/address.hpp>
3333
#include <boost/lexical_cast.hpp>
34-
#include <boost/optional.hpp>
3534
#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
3635

3736
#include <sql.h>
@@ -205,7 +204,7 @@ void FlightSqlConnection::PopulateMetadataSettings(
205204
metadata_settings_.chunk_buffer_capacity = GetChunkBufferCapacity(conn_property_map);
206205
}
207206

208-
boost::optional<int32_t> FlightSqlConnection::GetStringColumnLength(
207+
std::optional<int32_t> FlightSqlConnection::GetStringColumnLength(
209208
const Connection::ConnPropertyMap& conn_property_map) {
210209
const int32_t min_string_column_length = 1;
211210

@@ -220,7 +219,7 @@ boost::optional<int32_t> FlightSqlConnection::GetStringColumnLength(
220219
"01000", ODBCErrorCodes_GENERAL_WARNING);
221220
}
222221

223-
return boost::none;
222+
return std::nullopt;
224223
}
225224

226225
bool FlightSqlConnection::GetUseWideChar(const ConnPropertyMap& conn_property_map) {
@@ -256,7 +255,7 @@ const FlightCallOptions& FlightSqlConnection::PopulateCallOptions(
256255
const ConnPropertyMap& props) {
257256
// Set CONNECTION_TIMEOUT attribute or LOGIN_TIMEOUT depending on if this
258257
// is the first request.
259-
const boost::optional<Connection::Attribute>& connection_timeout =
258+
const std::optional<Connection::Attribute>& connection_timeout =
260259
closed_ ? GetAttribute(LOGIN_TIMEOUT) : GetAttribute(CONNECTION_TIMEOUT);
261260
if (connection_timeout && boost::get<uint32_t>(*connection_timeout) > 0) {
262261
call_options_.timeout =
@@ -394,17 +393,21 @@ bool FlightSqlConnection::SetAttribute(Connection::AttributeId attribute,
394393
}
395394
}
396395

397-
boost::optional<Connection::Attribute> FlightSqlConnection::GetAttribute(
396+
std::optional<Connection::Attribute> FlightSqlConnection::GetAttribute(
398397
Connection::AttributeId attribute) {
399398
switch (attribute) {
400399
case ACCESS_MODE:
401400
// FlightSQL does not provide this metadata.
402-
return boost::make_optional(Attribute(static_cast<uint32_t>(SQL_MODE_READ_WRITE)));
401+
return std::make_optional(Attribute(static_cast<uint32_t>(SQL_MODE_READ_WRITE)));
403402
case PACKET_SIZE:
404-
return boost::make_optional(Attribute(static_cast<uint32_t>(0)));
403+
return std::make_optional(Attribute(static_cast<uint32_t>(0)));
405404
default:
406405
const auto& it = attribute_.find(attribute);
407-
return boost::make_optional(it != attribute_.end(), it->second);
406+
if (it != attribute_.end()) {
407+
return std::make_optional(it->second);
408+
} else {
409+
return std::nullopt;
410+
}
408411
}
409412
}
410413

cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "arrow/flight/sql/odbc/odbc_impl/spi/connection.h"
2121

22+
#include <optional>
2223
#include <vector>
2324
#include "arrow/flight/api.h"
2425
#include "arrow/flight/sql/api.h"
@@ -91,7 +92,7 @@ class FlightSqlConnection : public Connection {
9192

9293
bool SetAttribute(AttributeId attribute, const Attribute& value) override;
9394

94-
boost::optional<Connection::Attribute> GetAttribute(
95+
std::optional<Connection::Attribute> GetAttribute(
9596
Connection::AttributeId attribute) override;
9697

9798
Info GetInfo(uint16_t info_type) override;
@@ -119,8 +120,7 @@ class FlightSqlConnection : public Connection {
119120
/// \note Visible for testing
120121
void SetClosed(bool is_closed);
121122

122-
boost::optional<int32_t> GetStringColumnLength(
123-
const ConnPropertyMap& conn_property_map);
123+
std::optional<int32_t> GetStringColumnLength(const ConnPropertyMap& conn_property_map);
124124

125125
bool GetUseWideChar(const ConnPropertyMap& conn_property_map);
126126

cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_connection_test.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "arrow/flight/types.h"
2222
#include "gtest/gtest.h"
2323

24+
#include <optional>
25+
2426
namespace arrow::flight::sql::odbc {
2527

2628
using arrow::flight::Location;
@@ -31,7 +33,7 @@ TEST(AttributeTests, SetAndGetAttribute) {
3133
connection.SetClosed(false);
3234

3335
connection.SetAttribute(Connection::CONNECTION_TIMEOUT, static_cast<uint32_t>(200));
34-
const boost::optional<Connection::Attribute> first_value =
36+
const std::optional<Connection::Attribute> first_value =
3537
connection.GetAttribute(Connection::CONNECTION_TIMEOUT);
3638

3739
EXPECT_TRUE(first_value);
@@ -40,7 +42,7 @@ TEST(AttributeTests, SetAndGetAttribute) {
4042

4143
connection.SetAttribute(Connection::CONNECTION_TIMEOUT, static_cast<uint32_t>(300));
4244

43-
const boost::optional<Connection::Attribute> change_value =
45+
const std::optional<Connection::Attribute> change_value =
4446
connection.GetAttribute(Connection::CONNECTION_TIMEOUT);
4547

4648
EXPECT_TRUE(change_value);
@@ -52,7 +54,7 @@ TEST(AttributeTests, SetAndGetAttribute) {
5254
TEST(AttributeTests, GetAttributeWithoutSetting) {
5355
FlightSqlConnection connection(OdbcVersion::V_3);
5456

55-
const boost::optional<Connection::Attribute> optional =
57+
const std::optional<Connection::Attribute> optional =
5658
connection.GetAttribute(Connection::CONNECTION_TIMEOUT);
5759
connection.SetClosed(false);
5860

@@ -77,7 +79,7 @@ TEST(MetadataSettingsTest, StringColumnLengthTest) {
7779
std::to_string(expected_string_column_length)},
7880
};
7981

80-
const boost::optional<int32_t> actual_string_column_length =
82+
const std::optional<int32_t> actual_string_column_length =
8183
connection.GetStringColumnLength(properties);
8284

8385
EXPECT_TRUE(actual_string_column_length);

cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_statement.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
3030
#include "arrow/io/memory.h"
3131

32-
#include <boost/optional.hpp>
32+
#include <optional>
3333
#include <utility>
3434
#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
3535

@@ -109,13 +109,17 @@ bool FlightSqlStatement::SetAttribute(StatementAttributeId attribute,
109109
}
110110
}
111111

112-
boost::optional<Statement::Attribute> FlightSqlStatement::GetAttribute(
112+
std::optional<Statement::Attribute> FlightSqlStatement::GetAttribute(
113113
StatementAttributeId attribute) {
114114
const auto& it = attribute_.find(attribute);
115-
return boost::make_optional(it != attribute_.end(), it->second);
115+
if (it != attribute_.end()) {
116+
return std::make_optional(it->second);
117+
} else {
118+
return std::nullopt;
119+
}
116120
}
117121

118-
boost::optional<std::shared_ptr<ResultSetMetadata>> FlightSqlStatement::Prepare(
122+
std::optional<std::shared_ptr<ResultSetMetadata>> FlightSqlStatement::Prepare(
119123
const std::string& query) {
120124
ClosePreparedStatementIfAny(prepared_statement_, call_options_);
121125

@@ -127,7 +131,7 @@ boost::optional<std::shared_ptr<ResultSetMetadata>> FlightSqlStatement::Prepare(
127131

128132
const auto& result_set_metadata = std::make_shared<FlightSqlResultSetMetadata>(
129133
prepared_statement_->dataset_schema(), metadata_settings_);
130-
return boost::optional<std::shared_ptr<ResultSetMetadata>>(result_set_metadata);
134+
return std::optional<std::shared_ptr<ResultSetMetadata>>(result_set_metadata);
131135
}
132136

133137
bool FlightSqlStatement::ExecutePrepared() {

cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_statement.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "arrow/flight/sql/api.h"
2727
#include "arrow/flight/types.h"
2828

29+
#include <optional>
30+
2931
namespace arrow::flight::sql::odbc {
3032

3133
class FlightSqlStatement : public Statement {
@@ -55,9 +57,9 @@ class FlightSqlStatement : public Statement {
5557

5658
bool SetAttribute(StatementAttributeId attribute, const Attribute& value) override;
5759

58-
boost::optional<Attribute> GetAttribute(StatementAttributeId attribute) override;
60+
std::optional<Attribute> GetAttribute(StatementAttributeId attribute) override;
5961

60-
boost::optional<std::shared_ptr<ResultSetMetadata>> Prepare(
62+
std::optional<std::shared_ptr<ResultSetMetadata>> Prepare(
6163
const std::string& query) override;
6264

6365
bool ExecutePrepared() override;

cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_stream_chunk_buffer.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ FlightStreamChunkBuffer::FlightStreamChunkBuffer(
6969
// call. temp_flight_sql_client is intentionally null if the list of endpoint
7070
// Locations is empty.
7171
// After all data is fetched from reader, the temp client is closed.
72-
return boost::make_optional(
73-
is_not_ok || is_not_empty,
74-
std::make_pair(std::move(result), temp_flight_sql_client));
72+
if (is_not_ok || is_not_empty) {
73+
return std::make_optional(
74+
std::make_pair(std::move(result), temp_flight_sql_client));
75+
} else {
76+
return std::optional<
77+
std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>>{};
78+
}
7579
};
7680
queue_.AddProducer(std::move(supplier));
7781
}

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <boost/xpressive/xpressive.hpp>
3737
#include <iterator>
3838
#include <memory>
39+
#include <optional>
3940
#include <utility>
4041

4142
using ODBC::ODBCConnection;
@@ -525,7 +526,7 @@ SQLRETURN ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
525526
SQLINTEGER buffer_length,
526527
SQLINTEGER* output_length, bool is_unicode) {
527528
using arrow::flight::sql::odbc::Connection;
528-
boost::optional<Connection::Attribute> spi_attribute;
529+
std::optional<Connection::Attribute> spi_attribute;
529530

530531
switch (attribute) {
531532
// Internal connection attributes

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include <sql.h>
3030
#include <sqlext.h>
3131
#include <sqltypes.h>
32-
#include <boost/optional.hpp>
3332
#include <boost/variant.hpp>
33+
#include <optional>
3434
#include <utility>
3535

3636
using ODBC::DescriptorRecord;
@@ -284,7 +284,7 @@ void ODBCStatement::CopyAttributesFromConnection(ODBCConnection& connection) {
284284
bool ODBCStatement::IsPrepared() const { return is_prepared_; }
285285

286286
void ODBCStatement::Prepare(const std::string& query) {
287-
boost::optional<std::shared_ptr<ResultSetMetadata> > metadata =
287+
std::optional<std::shared_ptr<ResultSetMetadata> > metadata =
288288
spi_statement_->Prepare(query);
289289

290290
if (metadata) {
@@ -378,7 +378,7 @@ void ODBCStatement::GetStmtAttr(SQLINTEGER statement_attribute, SQLPOINTER outpu
378378
SQLINTEGER buffer_size, SQLINTEGER* str_len_ptr,
379379
bool is_unicode) {
380380
using arrow::flight::sql::odbc::Statement;
381-
boost::optional<Statement::Attribute> spi_attribute;
381+
std::optional<Statement::Attribute> spi_attribute;
382382
switch (statement_attribute) {
383383
// Descriptor accessor attributes
384384
case SQL_ATTR_APP_PARAM_DESC:

0 commit comments

Comments
 (0)